0

我有这些值的例子:

$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;
4

2 回答 2

2

这就是unset

foreach ( $waiting['s9d8393838333'] as $key => $array ) {
    if ( $array['client_id'] == $clientID ) {
        unset( $waiting['s9d8393838333'][$key] );
        break;
    }
}

在此处查看实际操作:http ://codepad.viper-7.com/6dmr3N

于 2013-08-21T18:01:46.663 回答
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

工作示例:http ://codepad.viper-7.com/ut9UpS

于 2013-08-21T18:03:03.333 回答