I have problem with make automatic tree of arrays in PHP. Ex. i have numbers in my array: 2, 3, 3, and i can manulally make tree.
<?
$source_arr = array(2,3,3);
for($x=0; $x<$source_arr[0]; $x++){ // level 0: 2 loops
for ($xx=0; $xx<$source_arr[1]; $xx++) { // level 1: 3 loops
for ($xxx=0; $xxx<$source_arr[2]; $xxx++) { // level 2: 3 loops
$new[] = "$x$xx$xxx";
}
}
}
echo "<pre>";
print_r($new);
echo "</pre>";
?>
result:
Array ( [0] => 000 [1] => 001 [2] => 002 [3] => 010 [4] => 011 [5] => 012 [6] => 020 [7] => 021 [8] => 022 [9] => 100 [10] => 101 [11] => 102 [12] => 110 [13] => 111 [14] => 112 [15] => 120 [16] => 121 [17] => 122 )
But i want to automate it, i have different numbers of levels arrays with different values, like this: 11 levels:
$source_arr = array(8,5,10,12,5,8,12,5,6,10,8);
And i want to build automatic large tree. Is it possible with PHP array_walk or array_walk_recursive ? I found posts about building recursive categories tree, but i can not adapt those codes.
edit: i do not want to do infinity array and achieve memory exhaustion. My array count is never larger than 15 items, values range: 3-16.