2
Array
(
[9-1] => Array
    (
        [intensity] => 1
        [time] => 43932
    )

[9-2] => Array
    (
        [intensity] => 1
    )

[85-1] => Array
    (
        [intensity] => 1
        [time] => 40271
    )

[85-2] => Array
    (
        [intensity] => 1
    )

)

How would I remove the sub-arrays that have only 1 key, and that is 'intensity'?

4

2 に答える 2

6
$array = array_filter($array, function (array $i) {
    return count($i) != 1 || key($i) != 'intensity';
});
于 2012-12-26T13:55:18.933 に答える
3
foreach($yourArray as $key => $value)
  if (is_array($value) && count($value) == 1 && isset($value['intensity']))
    unset($yourArray[$key]);
于 2012-12-26T13:56:03.983 に答える