class Person { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $person = new Person("John", 30); $array = $person->toArray();
$user = [ "name" => "Anna", "email" => "anna@example.com", "password" => "123456" ]; $userObject = (object)$user; $userArray = (array)$userObject;In this example, we have created an array variable $user with three key-value pairs. Then, we have used type casting to convert the array into an object ($userObject) and then used the toArray() method to convert the object into an array ($userArray). The package library for the toArray() method is likely to be the core PHP library as it is an inbuilt method.