<?php
$root = array( 1=>'cat1', 2=>'cat2', 3=>'cat3' );
$child_1 = array( 1=>'sub_cat1', 2=>'sub_cat2', 3=>'sub_cat3' );
$child_2 = array( 1=>'sub_sub_cat1', 2=>'sub_sub_cat2', 3=>'sub_sub_cat3' );
function getAllCombinationsArray($source_arrays = array(), $key = '', $value = ''){
$return = array();
$current = array_shift($source_arrays);
foreach($current as $ck => $cv) {
$ckey = $key.$ck;
$cvalue = $value.$cv;
if(!empty($source_arrays)) {
$return += getAllCombinationsArray($source_arrays, $ckey.'_', $cvalue.' -> ');
} else {
$return[$ckey] = $cvalue;
}
return $return;
}
print_r(getAllCombinationsArray(array($root, $child_1, $child_2)));
- Output for 5.4.0 - 5.4.34
- Parse error: syntax error, unexpected end of file in /in/khjJh on line 24
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected $end in /in/khjJh on line 24
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected $ in /in/khjJh on line 24
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/khjJh on line 24
Process exited with code 255.
preferences:
204.93 ms | 1395 KiB | 124 Q