0

this is my array i want to process.

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

after trying array_push

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

             array_push($alreadyassingorder,$order);

            }
        }

the output is

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

the output i want

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

4
  • Use array_merge instead of array_push Commented Jan 27, 2016 at 7:35
  • @u_mulder did that but not getting the required output Commented Jan 27, 2016 at 7:37
  • did you try loop with array_push? i mean foreach($order as $index=>$key) array_push($alreadyassingorder,$key); ? Commented Jan 27, 2016 at 7:46
  • @MohsenShakibafar thanks it worked kindly post as answer. Commented Jan 27, 2016 at 7:49

1 Answer 1

1

Try like this:

$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;

            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.