I have a $products array like this:
Array
(
[0] => Array
(
[0] => 1001
[1] => 1002
)
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
)
I want to loop through it and create a one-level array comprised only of the non-empty array data like this:
$newArr = [
[0] => 1001,
[1] => 1002
]
My foreach loop that I thought would work throws an error ('Invalid argument supplied for foreach()'
).
The foreach loop looks like this:
$idArr = [];
foreach($products as $value) {
foreach ($value as $id) {
echo $id . '<br>';
$idArr[] = $id;
}
}
The two values echo suggesting the code is correct, but it's not. I am unable to store the iterated $id value into $idArr[]
.
If anyone can spot my error or errors, I would appreciate it.
Thanks!