3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $configArray = array( 'nominal' => array( 'before' => array('subtotal'), 'after' => array(), '_code' => 'nominal', ), 'subtotal' => array( 'after' => array('nominal'), 'before' => array('grand_total'), '_code' => 'subtotal', ), 'shipping' => array( 'after' => array('subtotal', 'freeshipping', 'tax_subtotal'), 'before' => array('grand_total'), '_code' => 'shipping', ), 'grand_total' => array( 'after' => array( 0 => 'subtotal', ), 'before' => array(), '_code' => 'grand_total', ), 'msrp' => array( 'before' => array(), 'after' => array(), '_code' => 'msrp', ), 'freeshipping' => array( 'after' => array( 0 => 'subtotal', ), 'before' => array( 0 => 'tax_subtotal', 1 => 'shipping', ), '_code' => 'freeshipping', ), 'discount' => array( 'after' => array( 0 => 'subtotal', 1 => 'shipping', ), 'before' => array( 0 => 'grand_total', ), '_code' => 'discount', ), 'tax_subtotal' => array( 'after' => array( 0 => 'freeshipping', ), 'before' => array( 0 => 'tax', 1 => 'discount', ), '_code' => 'tax_subtotal', ), 'tax_shipping' => array( 'after' => array( 0 => 'shipping', 1 => 'tax_subtotal', ), 'before' => array( 0 => 'tax', 1 => 'discount', ), '_code' => 'tax_shipping', ), 'tax' => array( 'after' => array( 0 => 'subtotal', 1 => 'shipping', 2 => 'discount', ), 'before' => array( 0 => 'grand_total', ), '_code' => 'tax', ), ); 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']); } foreach ($data['after'] as $afterCode) { if (!isset($configArray[$afterCode])) { continue; } $configArray[$code]['after'] = array_unique( array_merge( $configArray[$code]['after'], $configArray[$afterCode]['after'] ) ); $configArray[$afterCode]['before'] = array_merge( $configArray[$afterCode]['before'], array($code), $data['before'] ); $configArray[$afterCode]['before'] = array_unique($configArray[$afterCode]['before']); } } uasort($configArray, 'compareTotals'); print_r($configArray);
based on rBVB7
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: uasort() expects parameter 2 to be a valid callback, function 'compareTotals' not found or invalid function name in /in/Cotso on line 146 Array ( [nominal] => Array ( [before] => Array ( [0] => subtotal [1] => grand_total ) [after] => Array ( ) [_code] => nominal ) [subtotal] => Array ( [after] => Array ( [0] => nominal ) [before] => Array ( [0] => grand_total [1] => shipping [2] => freeshipping [3] => tax_subtotal [4] => discount [5] => tax ) [_code] => subtotal ) [shipping] => Array ( [after] => Array ( [0] => subtotal [1] => freeshipping [2] => tax_subtotal [3] => nominal ) [before] => Array ( [0] => grand_total [1] => discount [2] => tax_shipping [3] => tax ) [_code] => shipping ) [grand_total] => Array ( [after] => Array ( [0] => subtotal [1] => nominal [2] => shipping [3] => freeshipping [4] => tax_subtotal [5] => discount [6] => tax ) [before] => Array ( ) [_code] => grand_total ) [msrp] => Array ( [before] => Array ( ) [after] => Array ( ) [_code] => msrp ) [freeshipping] => Array ( [after] => Array ( [0] => subtotal [1] => nominal ) [before] => Array ( [0] => tax_subtotal [1] => shipping [2] => grand_total [3] => tax [4] => discount ) [_code] => freeshipping ) [discount] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => nominal [3] => freeshipping [4] => tax_subtotal [5] => tax_shipping ) [before] => Array ( [0] => grand_total [1] => tax ) [_code] => discount ) [tax_subtotal] => Array ( [after] => Array ( [0] => freeshipping [1] => subtotal [3] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => shipping [3] => grand_total [4] => tax_shipping ) [_code] => tax_subtotal ) [tax_shipping] => Array ( [after] => Array ( [0] => shipping [1] => tax_subtotal [2] => subtotal [3] => freeshipping [4] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => grand_total ) [_code] => tax_shipping ) [tax] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => discount [3] => tax_subtotal [4] => freeshipping [5] => tax_shipping [6] => nominal ) [before] => Array ( [0] => grand_total ) [_code] => tax ) )
Output for hhvm-3.10.0 - 3.12.0
Warning: Invalid argument: function: method 'compareTotals' not found in /in/Cotso on line 146 Array ( [nominal] => Array ( [before] => Array ( [0] => subtotal [1] => grand_total ) [after] => Array ( ) [_code] => nominal ) [subtotal] => Array ( [after] => Array ( [0] => nominal ) [before] => Array ( [0] => grand_total [1] => shipping [2] => freeshipping [3] => tax_subtotal [4] => discount [5] => tax ) [_code] => subtotal ) [shipping] => Array ( [after] => Array ( [0] => subtotal [1] => freeshipping [2] => tax_subtotal [3] => nominal ) [before] => Array ( [0] => grand_total [1] => discount [2] => tax_shipping [3] => tax ) [_code] => shipping ) [grand_total] => Array ( [after] => Array ( [0] => subtotal [1] => nominal [2] => shipping [3] => freeshipping [4] => tax_subtotal [5] => discount [6] => tax ) [before] => Array ( ) [_code] => grand_total ) [msrp] => Array ( [before] => Array ( ) [after] => Array ( ) [_code] => msrp ) [freeshipping] => Array ( [after] => Array ( [0] => subtotal [1] => nominal ) [before] => Array ( [0] => tax_subtotal [1] => shipping [2] => grand_total [3] => tax [4] => discount ) [_code] => freeshipping ) [discount] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => nominal [3] => freeshipping [4] => tax_subtotal [5] => tax_shipping ) [before] => Array ( [0] => grand_total [1] => tax ) [_code] => discount ) [tax_subtotal] => Array ( [after] => Array ( [0] => freeshipping [1] => subtotal [3] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => shipping [3] => grand_total [4] => tax_shipping ) [_code] => tax_subtotal ) [tax_shipping] => Array ( [after] => Array ( [0] => shipping [1] => tax_subtotal [2] => subtotal [3] => freeshipping [4] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => grand_total ) [_code] => tax_shipping ) [tax] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => discount [3] => tax_subtotal [4] => freeshipping [5] => tax_shipping [6] => nominal ) [before] => Array ( [0] => grand_total ) [_code] => tax ) )
Output for 5.2.5 - 5.2.17
Warning: uasort(): Invalid comparison function in /in/Cotso on line 146 Array ( [nominal] => Array ( [before] => Array ( [0] => subtotal [1] => grand_total ) [after] => Array ( ) [_code] => nominal ) [subtotal] => Array ( [after] => Array ( [0] => nominal ) [before] => Array ( [0] => grand_total [1] => shipping [2] => freeshipping [3] => tax_subtotal [4] => discount [5] => tax ) [_code] => subtotal ) [shipping] => Array ( [after] => Array ( [0] => subtotal [1] => freeshipping [2] => tax_subtotal [3] => nominal ) [before] => Array ( [0] => grand_total [1] => discount [2] => tax_shipping [3] => tax ) [_code] => shipping ) [grand_total] => Array ( [after] => Array ( [0] => subtotal [1] => nominal [2] => shipping [3] => freeshipping [4] => tax_subtotal [5] => discount [6] => tax ) [before] => Array ( ) [_code] => grand_total ) [msrp] => Array ( [before] => Array ( ) [after] => Array ( ) [_code] => msrp ) [freeshipping] => Array ( [after] => Array ( [0] => subtotal [1] => nominal ) [before] => Array ( [0] => tax_subtotal [1] => shipping [2] => grand_total [3] => tax [4] => discount ) [_code] => freeshipping ) [discount] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => nominal [3] => freeshipping [4] => tax_subtotal [5] => tax_shipping ) [before] => Array ( [0] => grand_total [1] => tax ) [_code] => discount ) [tax_subtotal] => Array ( [after] => Array ( [0] => freeshipping [1] => subtotal [3] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => shipping [3] => grand_total [4] => tax_shipping ) [_code] => tax_subtotal ) [tax_shipping] => Array ( [after] => Array ( [0] => shipping [1] => tax_subtotal [2] => subtotal [3] => freeshipping [4] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => grand_total ) [_code] => tax_shipping ) [tax] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => discount [3] => tax_subtotal [4] => freeshipping [5] => tax_shipping [6] => nominal ) [before] => Array ( [0] => grand_total ) [_code] => tax ) )
Output for 4.3.9 - 5.2.4
Warning: uasort(): Invalid comparison function. in /in/Cotso on line 146 Array ( [nominal] => Array ( [before] => Array ( [0] => subtotal [1] => grand_total ) [after] => Array ( ) [_code] => nominal ) [subtotal] => Array ( [after] => Array ( [0] => nominal ) [before] => Array ( [0] => grand_total [1] => shipping [2] => freeshipping [3] => tax_subtotal [4] => discount [5] => tax ) [_code] => subtotal ) [shipping] => Array ( [after] => Array ( [0] => subtotal [1] => freeshipping [2] => tax_subtotal [3] => nominal ) [before] => Array ( [0] => grand_total [1] => discount [2] => tax_shipping [3] => tax ) [_code] => shipping ) [grand_total] => Array ( [after] => Array ( [0] => subtotal [1] => nominal [2] => shipping [3] => freeshipping [4] => tax_subtotal [5] => discount [6] => tax ) [before] => Array ( ) [_code] => grand_total ) [msrp] => Array ( [before] => Array ( ) [after] => Array ( ) [_code] => msrp ) [freeshipping] => Array ( [after] => Array ( [0] => subtotal [1] => nominal ) [before] => Array ( [0] => tax_subtotal [1] => shipping [2] => grand_total [3] => tax [4] => discount ) [_code] => freeshipping ) [discount] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => nominal [3] => freeshipping [4] => tax_subtotal [5] => tax_shipping ) [before] => Array ( [0] => grand_total [1] => tax ) [_code] => discount ) [tax_subtotal] => Array ( [after] => Array ( [0] => freeshipping [1] => subtotal [3] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => shipping [3] => grand_total [4] => tax_shipping ) [_code] => tax_subtotal ) [tax_shipping] => Array ( [after] => Array ( [0] => shipping [1] => tax_subtotal [2] => subtotal [3] => freeshipping [4] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => grand_total ) [_code] => tax_shipping ) [tax] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => discount [3] => tax_subtotal [4] => freeshipping [5] => tax_shipping [6] => nominal ) [before] => Array ( [0] => grand_total ) [_code] => tax ) )
Output for 4.3.0 - 4.3.8
Array ( [discount] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => nominal [3] => freeshipping [4] => tax_subtotal [5] => tax_shipping ) [before] => Array ( [0] => grand_total [1] => tax ) [_code] => discount ) [tax_subtotal] => Array ( [after] => Array ( [0] => freeshipping [1] => subtotal [3] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => shipping [3] => grand_total [4] => tax_shipping ) [_code] => tax_subtotal ) [tax_shipping] => Array ( [after] => Array ( [0] => shipping [1] => tax_subtotal [2] => subtotal [3] => freeshipping [4] => nominal ) [before] => Array ( [0] => tax [1] => discount [2] => grand_total ) [_code] => tax_shipping ) [tax] => Array ( [after] => Array ( [0] => subtotal [1] => shipping [2] => discount [3] => tax_subtotal [4] => freeshipping [5] => tax_shipping [6] => nominal ) [before] => Array ( [0] => grand_total ) [_code] => tax ) [freeshipping] => Array ( [after] => Array ( [0] => subtotal [1] => nominal ) [before] => Array ( [0] => tax_subtotal [1] => shipping [2] => grand_total [3] => tax [4] => discount ) [_code] => freeshipping ) [msrp] => Array ( [before] => Array ( ) [after] => Array ( ) [_code] => msrp ) [subtotal] => Array ( [after] => Array ( [0] => nominal ) [before] => Array ( [0] => grand_total [1] => shipping [2] => freeshipping [3] => tax_subtotal [4] => discount [5] => tax ) [_code] => subtotal ) [shipping] => Array ( [after] => Array ( [0] => subtotal [1] => freeshipping [2] => tax_subtotal [3] => nominal ) [before] => Array ( [0] => grand_total [1] => discount [2] => tax_shipping [3] => tax ) [_code] => shipping ) [grand_total] => Array ( [after] => Array ( [0] => subtotal [1] => nominal [2] => shipping [3] => freeshipping [4] => tax_subtotal [5] => discount [6] => tax ) [before] => Array ( ) [_code] => grand_total ) [nominal] => Array ( [before] => Array ( [0] => subtotal [1] => grand_total ) [after] => Array ( ) [_code] => nominal ) )