$user = JFactory::getUser(); //get current user object $userArray = JArrayHelper::fromObject($user); //convert object to array print_r($userArray); //print array for debugging
class Customer { public $name; public $email; } $customer = new Customer(); $customer->name = "John Smith"; $customer->email = "john@example.com"; $customerArray = JArrayHelper::fromObject($customer); //convert object to array print_r($customerArray); //print array for debuggingIn both examples, we use the JArrayHelper fromObject method to convert an object into an array. The resulting array is then printed to the screen using the PHP print_r function. The JArrayHelper class is part of the Joomla PHP framework's core package library (joomla\utilities).