5
我有一个像下面的数组(阵列1),我需要从它删除stdClass像下面的数组编号。 2.目前我正在使用foreach循环来做这件事,有没有更好的方式来做这种循环?从数组中删除stdClass对象
阵列一号
array(3) {
[0] => object(stdClass)#169 (4) {
["id"] => string(2) "59"
["name"] => string(13) "test"
["email"] => string(21) "[email protected]"
["telephone"] => string(20) "898998989"
}
[1] => object(stdClass)#190 (4) {
["id"] => string(2) "58"
["name"] => string(13) "test"
["email"] => string(21) "[email protected]"
["telephone"] => string(8) "71877858"
}
[2] => object(stdClass)#193 (4) {
["id"] => string(2) "34"
["name"] => string(9) "test"
["email"] => string(22) "[email protected]"
["telephone"] => string(13) "3189028092139"
}
}
阵列二号
array(3) {
[0] => array(4) {
["id"] => string(2) "62"
["name"] => string(5) "test"
["email"] => string(22) "[email protected]"
["telephone"] => string(10) "898998989"
}
[1] => array(4) {
["id"] => string(2) "59"
["name"] => string(13) "test"
["email"] => string(21) "[email protected]"
["telephone"] => string(20) "71877858"
}
[2] => array(4) {
["id"] => string(2) "58"
["name"] => string(13) "test"
["email"] => string(21) "[email protected]"
["telephone"] => string(8) "3189028092139"
}
}
这是我做的(铸造)
foreach($moderationContacts as $contact)
{
$contacts[] = (array)$contact;
}
为什么要删除它? – Bananam00n 2013-05-07 13:34:06
您不能在没有循环的情况下操作数组。任何解决方案都需要某种形式的隐式循环。 – deceze 2013-05-07 13:34:41
@ Bananam00n - 我需要使用json_encode – Shaolin 2013-05-07 13:34:44