3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined array key "after" in /in/5KbtG on line 27 Warning: Undefined array key "after" in /in/5KbtG on line 29 Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in /in/5KbtG:26 Stack trace: #0 /in/5KbtG(26): array_merge(NULL, Array, NULL) #1 {main} thrown in /in/5KbtG on line 26
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: Undefined array key "after" in /in/5KbtG on line 27 Warning: Undefined array key "after" in /in/5KbtG on line 29 Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in /in/5KbtG:29 Stack trace: #0 /in/5KbtG(29): array_merge(NULL, Array, NULL) #1 {main} thrown in /in/5KbtG on line 29
Process exited with code 255.
Output for 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined index: after in /in/5KbtG on line 27 Notice: Undefined index: after in /in/5KbtG on line 29 Warning: array_merge(): Expected parameter 1 to be an array, null given 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 7.3.32 - 7.3.33
Warning: array_merge(): Expected parameter 1 to be an array, null given 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 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33
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 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 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.0.5, 5.1.0 - 5.1.6, 5.2.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.3.11, 4.4.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 ) )

preferences:
221.26 ms | 403 KiB | 311 Q