So I have a foreach
loop which loops though an array of items. The checkIfSubCategorie()
returns an array with new items.
I want to place all these items in the $subcategorien
array. This works good. The problem is that those items don't go through the initial foreach loop. Is this possible and if yes, how?
foreach($subcategorien as $subcat) {
//make array with all subcategorien
$newarray = self::checkIfSubCategorie($subcat);
if(is_array($newarray)) {
foreach($newarray as $a) {
// add item to subcategorien
array_push($subcategorien, $a);
}
}
}
This is the $subcategorien
array before the initial foreach
loop:
array(2) {
[0]=> string(3) "701"
[1]=> string(3) "702"
}
var_dump of $newarray
:
array(1) {
[0]=> string(1) "8"
}
bool(false)
This is the $subcategorien
array after the foreach
loop:
array(3) {
[0]=> string(3) "701"
[1]=> string(3) "702"
[2]=> string(1) "8"
}
The result should be:
array(3) {
[0]=> string(3) "701"
[1]=> string(3) "702"
[2]=> string(1) "8"
[3]=> string(1) "9"
}