Hello!
There is a multidimensional array of $allCategories with unknown nesting, you need to make several one-dimensional arrays of 1 level from it, for this I wrote the function convertToSimpleArray .
To combine the result into a single array, use the line global $resArray; i.e. each time the function is called from the loop, the $resArray must be cleared, so, what is now written in the foreach loop does not work as it should, the $resArray not cleared, how to fix it?
function convertToSimpleArray($array){ global $resArray; if(is_array($array)){ foreach($array as $below){ $res = convertToSimpleArray($below); } } else { $resArray[] = $array; } return $resArray; } $simpleArraysCategories = []; $count = 0; foreach($allCategories as $category){ $resArray = []; $simpleArraysCategories[$count] = convertToSimpleArray($allCategories[$count]); $count++; } PS I'm new to php, come from js, at least there are closures there.
$categoryif you use$count- teranarray_walk_recursivefunction, maybe you will not need to fence a lot of code? - teran