Tags
Asked 2 years ago
30 Jul 2021
Views 152
john

john posted

How to convert an array to object in PHP?

How to convert an array to object in PHP?
Nilesh

Nilesh
answered Aug 30 '21 00:00

to convert simple array to object in PHP . use type conversion by object
see the below example for converting array to object in php

$l=array("a","b","c");
print_r((object)$l); // stdClass Object ( [0] => a [1] => b [2] => c ) 



object type conversation does not work for multidimensional array to multidimensional object
multidimensional array to multidimensional object example is as below :

$array= array(
"a","b"=>
	array("c","b",array("c","a")));
print_r((object)$array); // stdClass Object ( [0] => a [b] => Array ( [0] => c [1] => b [2] => Array ( [0] => c [1] => a ) ) )


Post Answer