Saturday, June 7, 2008

how to convert PHP array in to PHP object ?

$a = $array("a"=> 1, "b"=> 2);

now type cast array in to object...

$arrayObj = (object)$a;

now u able to use like object and method.....

echo $arrayObj->a; // output 1
echo $arrayObj->b;// output 2

but only work with key as a string.....not work with indexed array.

No comments: