通过内部元素将数组拆分为多个数组

时间:2015-03-28 12:55:51

标签: arrays split

[19] => Array
        (
            [date] => 2015-03-02
            [supervisor] => 16
            [avg] => 1.50
        )
[20] => Array
    (
        [date] => 2015-03-03
        [supervisor] => 16
        [avg] => 1.50
    )

[21] => Array
    (
        [date] => 2015-03-04
        [supervisor] => 16
        [avg] => 1.50
    )

[22] => Array
    (
        [date] => 2015-01-02
        [supervisor] => 26
        [avg] => 
    )

[23] => Array
    (
        [date] => 2015-01-05
        [supervisor] => 26
        [avg] => 
    )

我有这个数组。我想通过主管将这个单个数组拆分为2个数组 例如,这里只有2个不同的主管(16,26)。我想要两个单独的数组。
喜欢:
数组1:

[20] => Array
    (
        [date] => 2015-03-03
        [supervisor] => 16
        [avg] => 1.50
    )

[21] => Array
    (
        [date] => 2015-03-04
        [supervisor] => 16
        [avg] => 1.50
    )


Array 2: 
[22] => Array
    (
        [date] => 2015-01-02
        [supervisor] => 26
        [avg] => 
    )

[23] => Array
    (
        [date] => 2015-01-05
        [supervisor] => 26
        [avg] => 
    )

请帮帮我。

1 个答案:

答案 0 :(得分:0)

您是否尝试在PHP中执行此操作?

如果是这样..

为主管创建一个新数组

$supervisors = array();

首先循环当前数组

foreach($arr as $key => $value):
  $supervisor = $value['supervisor'];
  //Add more data to the array here
  $supervisors[$supervisor] = //Array of info you require
endforeach;