Converts an object or an array of objects into an array.
public static toArray ( object | array | string $object, array $properties = [], boolean $recursive = true ) : array | ||
$object | object | array | string | the object to be converted into an array |
$properties | array | a mapping from object class names to the properties that need to put into the resulting arrays. The properties specified for each class is an array of the following format: ```php [ 'app\models\Post' => [ 'id', 'title', // the key name in array result => property name 'createTime' => 'created_at', // the key name in array result => anonymous function 'length' => function ($post) { return strlen($post->content); }, ], ] ``` The result of `ArrayHelper::toArray($post, $properties)` could be like the following: ```php [ 'id' => 123, 'title' => 'test', 'createTime' => '2013-01-01 12:00AM', 'length' => 301, ] ``` |
$recursive | boolean | whether to recursively converts properties which are objects into arrays. |
return | array | the array representation of the object |