3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $configArray = array( 'grand_total' => array( 'before' => array(), '_code' => 'grand_total', ), 'discount' => array( 'before' => array('grand_total'), '_code' => 'discount', ), ); reset($configArray); $element = current($configArray); foreach ($configArray as $code => $data) { foreach ($data['before'] as $beforeCode) { if (!isset($configArray[$beforeCode])) { continue; } $configArray[$code]['before'] = array_unique( array_merge( $configArray[$code]['before'], $configArray[$beforeCode]['before'] ) ); $configArray[$beforeCode]['after'] = array_merge( $configArray[$beforeCode]['after'], array($code), $data['after'] ); $configArray[$beforeCode]['after'] = array_unique($configArray[$beforeCode]['after']); } } print_r($configArray);
based on nBh7h
Output for 7.0.0 - 7.1.0
Notice: Undefined index: after in /in/5KbtG on line 27 Notice: Undefined index: after in /in/5KbtG on line 29 Warning: array_merge(): Argument #1 is not an array in /in/5KbtG on line 29 Warning: array_unique() expects parameter 1 to be array, null given in /in/5KbtG on line 31 Array ( [grand_total] => Array ( [before] => Array ( ) [_code] => grand_total [after] => ) [discount] => Array ( [before] => Array ( [0] => grand_total ) [_code] => discount ) )
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: after in /in/5KbtG on line 27 Notice: Undefined index: after in /in/5KbtG on line 29 Warning: array_merge() expects parameter 1 to be array, null given in /in/5KbtG on line 30 Warning: Invalid operand type was used: expects array(s) in /in/5KbtG on line 31 Array ( [grand_total] => Array ( [before] => Array ( ) [_code] => grand_total [after] => ) [discount] => Array ( [before] => Array ( [0] => grand_total ) [_code] => discount ) )
Output for 5.3.0 - 5.6.28
Notice: Undefined index: after in /in/5KbtG on line 27 Notice: Undefined index: after in /in/5KbtG on line 29 Warning: array_merge(): Argument #1 is not an array in /in/5KbtG on line 30 Warning: array_unique() expects parameter 1 to be array, null given in /in/5KbtG on line 31 Array ( [grand_total] => Array ( [before] => Array ( ) [_code] => grand_total [after] => ) [discount] => Array ( [before] => Array ( [0] => grand_total ) [_code] => discount ) )
Output for 5.0.0 - 5.2.17
Notice: Undefined index: after in /in/5KbtG on line 27 Notice: Undefined index: after in /in/5KbtG on line 29 Warning: array_merge(): Argument #1 is not an array in /in/5KbtG on line 30 Warning: array_merge(): Argument #3 is not an array in /in/5KbtG on line 30 Warning: array_unique(): The argument should be an array in /in/5KbtG on line 31 Array ( [grand_total] => Array ( [before] => Array ( ) [_code] => grand_total [after] => ) [discount] => Array ( [before] => Array ( [0] => grand_total ) [_code] => discount ) )
Output for 4.3.0 - 4.4.9
Notice: Undefined index: after in /in/5KbtG on line 27 Notice: Undefined index: after in /in/5KbtG on line 29 Array ( [grand_total] => Array ( [before] => Array ( ) [_code] => grand_total [after] => Array ( [0] => discount ) ) [discount] => Array ( [before] => Array ( [0] => grand_total ) [_code] => discount ) )