我有一个如下所示的数组(数组 1),我需要从中删除 stdClass,如下面的数组所示。 2.目前我正在使用 foreach 循环来执行此操作,是否有更好的方法可以在不循环的情况下执行此操作?
阵列1号
array(3) {
[0] => object(stdClass)#169 (4) {
["id"] => string(2) "59"
["name"] => string(13) "test"
["email"] => string(21) "[email protected] /cdn-cgi/l/email-protection"
["telephone"] => string(20) "898998989"
}
[1] => object(stdClass)#190 (4) {
["id"] => string(2) "58"
["name"] => string(13) "test"
["email"] => string(21) "[email protected] /cdn-cgi/l/email-protection"
["telephone"] => string(8) "71877858"
}
[2] => object(stdClass)#193 (4) {
["id"] => string(2) "34"
["name"] => string(9) "test"
["email"] => string(22) "[email protected] /cdn-cgi/l/email-protection"
["telephone"] => string(13) "3189028092139"
}
}
2号阵
array(3) {
[0] => array(4) {
["id"] => string(2) "62"
["name"] => string(5) "test"
["email"] => string(22) "[email protected] /cdn-cgi/l/email-protection"
["telephone"] => string(10) "898998989"
}
[1] => array(4) {
["id"] => string(2) "59"
["name"] => string(13) "test"
["email"] => string(21) "[email protected] /cdn-cgi/l/email-protection"
["telephone"] => string(20) "71877858"
}
[2] => array(4) {
["id"] => string(2) "58"
["name"] => string(13) "test"
["email"] => string(21) "[email protected] /cdn-cgi/l/email-protection"
["telephone"] => string(8) "3189028092139"
}
}
这就是我所做的(选角)
foreach($moderationContacts as $contact)
{
$contacts[] = (array)$contact;
}
try
$array = json_decode( json_encode($array), true);
编辑:
我已经测试过这个案例,它有效:
$stdClass= new stdClass();
$stdClass->test = "foo";
$array = Array(
"a" => Array("b","c"),
"d" => $stdClass
);
$array = json_decode( json_encode($array), true);
var_dump($array);
OUTPUT
array
'a' =>
array
0 => string 'b' (length=1)
1 => string 'c' (length=1)
'd' =>
array
'test' => string 'foo' (length=3)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)