fork(1) download
  1. <?php
  2. $test = array("hello" => "world", "object" => array("bye" => "world"));
  3.  
  4. function cast($array) {
  5. if (!is_array($array)) return $array;
  6. foreach ($array as &$v) {
  7. $v = cast($v);
  8. }
  9. return (object) $array;
  10. }
  11. $result = cast($test);
  12.  
  13. var_dump($result);
  14.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
object(stdClass)#2 (2) {
  ["hello"]=>
  string(5) "world"
  ["object"]=>
  object(stdClass)#1 (1) {
    ["bye"]=>
    string(5) "world"
  }
}