从关联数组中删除具有单个元素的数组

时间:2018-08-28 07:12:15

标签: php arrays

我有一个数组

Array
(
    [0] => Array
        (
            [0] => 96
            [1] => ML based
            [7] => Open
        )

)
Array
(
    [0] => Array
        (
            [0] => 97
            [1] => Application 
            [7] => Open
        )

)
Array
(
    [0] => Array
        (
            [0] => 98
        )

)
Array
(
    [0] => Array
        (
            [0] => 99
        )

)

我要删除

Array
(
    [0] => Array
        (
            [0] => 98
        )

)
Array
(
    [0] => Array
        (
            [0] => 99
        )

)

来自此数组

我尝试过:

$data = array_map('array_filter', $rowData);
unset($data[0][0]); 

预期输出:

Array
(
[0] => Array
    (
        [0] => 96
        [1] => ML based )
        [7] => Open
    )

)
Array
(
[0] => Array
    (
        [0] => 97
        [1] => Application 
        [7] => Open
    )

)

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

array_filter()将起作用。试试-

array_filter($array, function ($a) {
    return count($a[0]) == 3; // return array with 3 elements only
});

Working code