如何通过数组中的值删除数组?

时间:2019-04-02 15:58:15

标签: php arrays

这是我的数组,我要删除键值为60138的数组。如何使用其值删除特定数组?

Array
    (
    [name] => Hydrangeas.jpg
    [keyval] => 23905
    )
    Array
    (
        [name] => Chrysanthemum.jpg
        [keyval] => 87936
    )
    Array
    (
        [name] => Penguins.jpg
        [keyval] => 60138
    )
    Array
    (
        [name] => Tulips.jpg
        [keyval] => 82902
    )

谢谢。

1 个答案:

答案 0 :(得分:1)

尝试一下:

$array = array(
    // here is all your array with name + keyval
);

// Loop throught each array
foreach ($array as $key => $subarray) {
    // If keyval has the value you want to delete : remove it from main $array
    if ($subarray['keyval'] == 60138) {
        unset($array[$key];
    }
}