3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php const ID_INDEX = 0; const NAME_INDEX = 1; $sections = array(array(1, 'Section 1'), array(2, 'Section B'), array(3, 'Just section')); $rubriques = array(array(1, 'Rubiq'), array(2, 'Rubrique'), array(3, 'Ruby')); $categories = array(array(1, 'Category A'), array(2, 'Category B'), array(3, 'Category C')); $output = array(); foreach($sections as $section) { $output[$section[NAME_INDEX]] = array($section[ID_INDEX]); foreach($rubriques as $rubrique) { $output[$section[NAME_INDEX]][$rubrique[NAME_INDEX]] = array($rubrique[ID_INDEX]); foreach($categories as $category) { $output[$section[NAME_INDEX]][$rubrique[NAME_INDEX]][$category[NAME_INDEX]][] = $category[ID_INDEX]; } } } var_dump($output);
Output for 5.3.0 - 7.3.0rc4
array(3) { ["Section 1"]=> array(4) { [0]=> int(1) ["Rubiq"]=> array(4) { [0]=> int(1) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } ["Rubrique"]=> array(4) { [0]=> int(2) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } ["Ruby"]=> array(4) { [0]=> int(3) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } } ["Section B"]=> array(4) { [0]=> int(2) ["Rubiq"]=> array(4) { [0]=> int(1) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } ["Rubrique"]=> array(4) { [0]=> int(2) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } ["Ruby"]=> array(4) { [0]=> int(3) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } } ["Just section"]=> array(4) { [0]=> int(3) ["Rubiq"]=> array(4) { [0]=> int(1) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } ["Rubrique"]=> array(4) { [0]=> int(2) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } ["Ruby"]=> array(4) { [0]=> int(3) ["Category A"]=> array(1) { [0]=> int(1) } ["Category B"]=> array(1) { [0]=> int(2) } ["Category C"]=> array(1) { [0]=> int(3) } } } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_CONST in /in/ou6rb on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CONST in /in/ou6rb on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ou6rb on line 2
Process exited with code 255.