-2

im recieveing an output in the following format.When i foreach the loop only one id is iterated i need to combine these array into one single array so i can iterate all the ids.

Array
(
    [0] => 6902680092829
)
Array
(
    [0] => 6902680125597
)
Array
(
    [0] => 6902680158365
)
Array
(
    [0] => 6902680223901
)
Array
(
    [0] => 6902680256669
)

i want to combine this array into one single array for eg:

array:{
0=>1,
1=>2,
2=>3
}

im adding shopify product id one by one to an array by doing this

$prdid=[];
    array_push($prdid,$shopifyCustomers['body']['container']['product']['id']);
5
  • What is the correlation between the current array and the desired output array? Commented Aug 9, 2021 at 7:17
  • @BenM THere is no corealtion im just showing how i want the array to be i.e second array Commented Aug 9, 2021 at 7:24
  • Does this answer your question? Php: array merge Commented Aug 9, 2021 at 7:31
  • @SibiKandathil no array merge is not the solution Commented Aug 9, 2021 at 7:49
  • Depending on how you get these arrays, you can take advantage of collection, that is why you should be using Laravel and dropping array_xxxxx methods (they are used behind scenes). So you can simply do $collection = collect(...$array1); and then, when you want to add another ID or whatever, just $collection->push($id); and that's it... Commented Sep 5, 2021 at 23:53

1 Answer 1

1

You can simply use array_merge()

$arr1 = [ 6902680092829 ];
$arr2 = [ 6902680125597 ];
$arr3 = [ 6902680158365 ];
$arr4 = [ 6902680223901 ];
$arr5 = [ 6902680256669 ];
$newArr = array_merge($arr1, $arr2, $arr3, $arr4, $arr5);
Sign up to request clarification or add additional context in comments.

3 Comments

The arrays are dynamically generated and it may have upto 20 different arrays so how can i merge them
Please add the code, how they are generated to your question.
You could use the splat operator instead. For example, $newArr = array_merge(...$oldArr);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.