RV Smart Site Blog

  • Published on Jul 26, 2012

    If you have an $arr = array("a"=>"1") ; [sourcecode language="php" toolbar="true"] * You want to print the element like $arr->a instead of this $arr["a"] . [/sourcecode] * Here I am right a function which convert your array into object * [sourcecode language="php" toolbar="true"] function bindArrayToObject($array) { $return = new stdClass(); foreach ($array as $k => $v) { if (is_array($v)) { $return->$k = bindArrayToObject($v); } else { $return->$k = $v; } } return $return; } Example : $data = array("a"=>"This is a" , "b"=>array("b1"=>"this is the b1") ) ; $dObj = bindArratToObject($data); echo $dObj->b->b1 ; // this is the b1 [/sourcecode]

    * reference : https://www.lost-in-code.com/programming/php-code/php-array-to-object/
0 Comments

 

© Copyright RV Smart Site 2024. All rights reserved.

Site secured by Comodo
Ride Digital