1

我有一个看起来像这样的数组:

MyArray (
    [0] => Array (
                            [board_id] => 1047999
                            [added_date] => 2013-02-28 11:14:02
                            [type] => 4
                           )
    [1] => Array (
                           [board_id] => 1047999
                           [added_date] => 2013-02-28 11:14:02
                           [type] => 1
                          )
    [2] => Array (
                          [board_id] => 1047999
                          [added_date] => 2013-02-28 11:14:02
                          [type] => 4
                          )
    [3] => Array (
                          [board_id] => 1047999
                          [added_date] => 2013-02-28 11:14:02
                          [type] => 1
                          )
)

如何拆分此数组type并保持完全相同的数组结构?即我将有两个子数组的 MyArrayT4 和两个子数组的 MyArrayT1?

蒂亚!

4

1 回答 1

2

像这样使用 array_filter 编辑使用 array_values 重置

$filtering = function($type) use($your_array) {
    $filtered = array_filter($your_array, function($r) use($type) {
        return $r['type'] == $type;
    });

    return array_values($filtered);
};


$array_1 = $filtering->__invoke('4');
$array_2 = $filtering->__invoke('1');
于 2013-03-03T21:16:32.953 回答