-
Notifications
You must be signed in to change notification settings - Fork 0
arrayToObject
Corey Avis edited this page Sep 23, 2026
·
2 revisions
Converts a PHP array into an object structure.
This method dynamically handles different array types:
- Associative Arrays: Directly converted into an object where keys become property names.
- Indexed Arrays: The method iterates through the array to check if its subarrays are associative. If a nested array is associative, it is recursively converted into an object, preserving the multidimensional structure where appropriate.
arrayToObject(array $array = []): array|object
array (array) : The array to convert.
(array|object) : Returns an object (or a mixed structure of arrays and objects) containing the converted data, depending on whether the top-level array was associtive or indexed.
$cphp->arrayToObject(['id' => 10, 'user' => 'name', 'active' => true])
// Result: ([id] => 10, [user] => "name", [active] => 1)
- No debug errors.
arrayToJson | arrayToSerial | objectToArray
Home | CoreyPHP | Conversion