[ create a new paste ] login | about

Link: http://codepad.org/Tr8rktjN    [ raw code | output | fork ]

PHP, pasted on Sep 16:
<?php

$o->prop->another->something->else = 'Hello';


var_dump($o);

    function object_to_array($object)
    {
    	if (is_array($object) OR is_object($object))
    	{
    		$result = array(); 
    		foreach($object as $key => $value)
    		{ 
    			$result[$key] = object_to_array($value); 
    		}
    		return $result;
    	}
    	return $object;
    }


var_dump(object_to_array($o));


Output:
object(stdClass)#1 (1) {
  ["prop"]=>
  object(stdClass)#2 (1) {
    ["another"]=>
    object(stdClass)#3 (1) {
      ["something"]=>
      object(stdClass)#4 (1) {
        ["else"]=>
        string(5) "Hello"
      }
    }
  }
}
array(1) {
  ["prop"]=>
  array(1) {
    ["another"]=>
    array(1) {
      ["something"]=>
      array(1) {
        ["else"]=>
        string(5) "Hello"
      }
    }
  }
}


Create a new paste based on this one


Comments: