static function object_to_array($obj) {
$class_name = "";
//获得类名
if(is_object($obj)){
$class_name = get_class($obj);
//这个 键带有类名的
$obj = (array)$obj;
$obj2 = array();
//key 中取出类名
foreach ($obj as $k => $v) {
//echo $class_name;
if($class_name){
//echo $k . PHP_EOL;
$k = str_replace($class_name, "", $k);
//unicode表达方式
$k = str_replace("\u{0000}", "", $k);
//echo $k. PHP_EOL;;
}
$obj2[$k] = $v;
//echo $k;
}
$obj = $obj2;
}else{
$obj = (array)$obj;
}
foreach ($obj as $k => $v) {
if (gettype($v) == 'resource') {
return;
}
if (gettype($v) == 'object' || gettype($v) == 'array') {
//echo $k;
$obj[$k] = (array)self::object_to_array($v);
//echo $k;
}
}
return $obj;
}
/**
* 数组 转 对象
*
* @param array $arr 数组
* @return object
*/
static function array_to_object($arr) {
if (gettype($arr) != 'array') {
return;
}
foreach ($arr as $k => $v) {
if (gettype($v) == 'array' || getType($v) == 'object') {
$arr[$k] = (object)array_to_object($v);
}
}
return (object)$arr;
}
结果 去掉类名
Array
(
[action] => user.getToken
[app_key] =>
[client_id] =>
[client_sign] =>
[timestamp] =>
[version] => 1.0
[sign] =>
[sign_method] => md5
[format] => json
[platform] =>
[language] => zh_CN
[data] => Array
(
[0] => userName
[1] => rebecca
[2] => passWord
[3] => 888
)
[auz_app_key] =>
[auz_sign] =>
)
没有去掉类名
Array
(
[com\winit\api\model\RequestMsgaction] => user.getToken
[com\winit\api\model\RequestMsgapp_key] =>
[com\winit\api\model\RequestMsgclient_id] =>
[com\winit\api\model\RequestMsgclient_sign] =>
[com\winit\api\model\RequestMsgtimestamp] =>
[com\winit\api\model\RequestMsgversion] => 1.0
[com\winit\api\model\RequestMsgsign] =>
[com\winit\api\model\RequestMsgsign_method] => md5
[com\winit\api\model\RequestMsgformat] => json
[com\winit\api\model\RequestMsgplatform] =>
[com\winit\api\model\RequestMsglanguage] => zh_CN
[com\winit\api\model\RequestMsgdata] => Array
(
[0] => userName
[1] => rebecca
[2] => passWord
[3] => 888
)
[com\winit\api\model\RequestMsgauz_app_key] =>
[com\winit\api\model\RequestMsgauz_sign] =>
)