如何从数组

时间:2016-01-27 07:33:11

标签: php arrays

这是我要处理的数组。

  

数组([0] =>数组([checklist_id] => 3 [order_id] => [id] => 1)   [1] =>数组([checklist_id] => 4 [order_id] => [id] => 2)[2] =>   数组([checklist_id] => 7 [order_id] => 8,9,10,11,12 [id] => 4));

尝试array_push

$alreadyassingorder=array();
        foreach ($collection as  $checklistorder) {
            if($checklistorder['order_id'])
            {
             $order=explode(',', $checklistorder['order_id']);

             array_push($alreadyassingorder,$order);

            }
        }

输出

  

数组([0] =>数组([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5   [5] => 6 [6] => 7)[1] =>阵列([0] => 8 [1] => 9 [2] => 10 [3] =>   11 [4] => 12))

我想要的输出

  

数组([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5   [5] => 6 [6] => 7)[7] => 8 [8] => 9 [9] => 10 [10] =>   11 [11] => 12))

1 个答案:

答案 0 :(得分:1)

试试这样:

$alreadyassingorder=array();
        foreach ($collection as  $checklistorder) {
            if($checklistorder['order_id'])
            {
             $order=explode(',', $checklistorder['order_id']);
             foreach($order as $index=>$key):     
               array_push($alreadyassingorder,$key);
             endforeach;

            }
        }