class User { public $name = "John"; public $email = "john@example.com"; public $age = 25; } $user = new User; $userArray = $user->toArray(); print_r($userArray);
Array ( [name] => John [email] => john@example.com [age] => 25 )
$userArray = array( 'name' => 'John', 'email' => 'john@example.com', 'age' => 25 ); $userArray = $userArray->toArray(); print_r($userArray);
Array ( [name] => John [email] => john@example.com [age] => 25 )The package library for this function is PHP's core library.