解析PHP将对象转换成数组的方法(兼容多维数组类型)

yipeiwu_com7年前PHP代码库
复制代码 代码如下:

 /**
  * @author 【宜配屋www.yipeiwu.com】
  * @date 2013-6-21
  * @todo 将对象转换成数组
  * @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;
 }

这样就可以了。

相关文章

php从数组中随机抽取一些元素的代码

复制代码 代码如下: <?php class getValues { public function inputValue($inputArray) { $this->inp...

php str_replace替换指定次数的方法详解

实例 把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai": <?php echo str_replace("world","...

php获取URL中带#号等特殊符号参数的解决方法

例如下面的PHP代码: 复制代码 代码如下: <?php echo $_GET['key']; ?> 当url为http://test.com/c.php&...

如何使用PHP往windows中添加用户

方法有一:   因为添加用户,所以你运行PHP程序的用户必须是管理员权限(Administrator),并且同时需要你的php.ini中的安全模式没有打开,并且关闭函...

PHP中strcmp()和strcasecmp()函数字符串比较用法分析

本文实例讲述了PHP中strcmp()和strcasecmp()函数字符串比较用法。分享给大家供大家参考,具体如下: 一、PHP中strcmp()函数用于比较两个字符串(区分大小写),其...