of is compatible with multidimensional array types

  • 2020-06-15 07:59:36
  • OfStack


 /**
  * @author  The home of the script 
  * @date 2013-6-21
  * @todo  Converts an object to an array 
  * @param unknown_type $obj
  * @return unknown
  */
 function object_to_array($obj){
  $_arr = is_object($obj) ? get_object_vars($obj) :$obj;
  foreach ($_arr as $key=>$val){
   $val = (is_array($val) || is_object($val)) ? $this->object_to_array($val):$val;
   $arr[$key] = $val;
  }
  return $arr;
 }

That will do.

Related articles: