我有这些值的例子:
$waiting['s9d8393838333'][] = array("client_id" => "2039833");
$waiting['s9d8393838333'][] = array("client_id" => "1039833");
如何从阵列中删除client_id?如果我要删除client_id => 2039833?
foreach ( $waiting as $e => $array):
if ( $array['client_id'] == $clientID):
//Here i should delete that index ???
endif;
endforeach;
答案 0 :(得分:2)
这就是unset
的用途:
foreach ( $waiting['s9d8393838333'] as $key => $array ) {
if ( $array['client_id'] == $clientID ) {
unset( $waiting['s9d8393838333'][$key] );
break;
}
}
在此处查看:[{3}}
答案 1 :(得分:1)
foreach ($waiting as $key => $array) {
foreach ($array as $key2 => $val) {
if ($val['client_id'] == $clientID) {
unset($waiting[$key][$key2]);
}//END IF
}//END FOREACH LOOP
}//END FOREACH LOOP
如果你想“保持逻辑”作为某人的投诉,请使用:
foreach ($waiting as $key => $array) {
foreach ($array as $key2 => $val) {
if ($val['client_id'] == $clientID) {
unset($waiting[$key][$key2]);
endif;
endforeach;
endforeach;
如果你想要更多或更少的东西,你可以改变client_id