【发布时间】:2017-08-03 14:26:42
【问题描述】:
我有一个包含 13 个元素的数组
$vcpes=
array:13 [▼
0 => array:23 [▼
"cpe_mac" => "665544332211"
"bandwidth_max_up" => 300000
"bandwidth_max_down" => 500000
"filter_icmp_inbound" => null
"dmz_enabled" => null
"dmz_host" => null
"vlan_id" => null
"dns" => []
"xdns_mode" => null
"cfprofileid" => null
"stub_response" => null
"acl_mode" => null
"portal_url" => null
"fullbandwidth_max_up" => null
"fullbandwidth_max_down" => null
"fullbandwidth_guaranty_up" => null
"fullbandwidth_guaranty_down" => null
"account_id" => 1000 // <--- Keep
"location_id" => null
"network_count" => null
"group_name" => null
"vse_id" => null
"firewall_enabled" => null
]
1 => array:23 [▼
"cpe_mac" => "213243546576"
"bandwidth_max_up" => null
"bandwidth_max_down" => null
"filter_icmp_inbound" => null
"dmz_enabled" => null
"dmz_host" => null
"vlan_id" => null
"dns" => []
"xdns_mode" => null
"cfprofileid" => null
"stub_response" => null
"acl_mode" => null
"portal_url" => null
"fullbandwidth_max_up" => null
"fullbandwidth_max_down" => null
"fullbandwidth_guaranty_up" => null
"fullbandwidth_guaranty_down" => null
"account_id" => null // <--- Delete
"location_id" => null
"network_count" => null
"group_name" => null
"vse_id" => null
"firewall_enabled" => null
]
2 => array:23 [▶]
3 => array:23 [▶]
4 => array:23 [▶]
5 => array:23 [▶]
6 => array:23 [▶]
7 => array:23 [▶]
8 => array:23 [▶]
9 => array:23 [▶]
10 => array:23 [▶]
11 => array:23 [▶]
12 => array:23 [▶]
]
我想删除那些有account_id == null的。
我试图解码它:
$vcpes = json_decode (json_encode ( $vcpes), FALSE);
并检查它:
foreach($vcpes as $vcpe){
if($vcpe->account_id == null){
//delete it
}else{
//don't delete it
}
}
希望有人能给我一点提示。
【问题讨论】:
-
if($vcpe['account_id'] == null) -
$result = array_filter($originalArray, function($value) { return $value['account_id'] !== null; });