3v4l.org

run code in 300+ PHP versions simultaneously
<?php $configArray = array( 'grand_total' => array( 'class' => 'sales/quote_address_total_grand', 'after' => array( 0 => 'subtotal', ), 'renderer' => 'tax/checkout_grandtotal', 'admin_renderer' => 'adminhtml/sales_order_create_totals_grandtotal', 'before' => array(), '_code' => 'grand_total', ), 'discount' => array( 'class' => 'salesrule/quote_discount', 'after' => array( 0 => 'subtotal', 1 => 'shipping', ), 'before' => array( 0 => 'grand_total', ), 'admin_renderer' => 'adminhtml/sales_order_create_totals_discount', 'renderer' => 'amrules/checkout_discount', '_code' => 'discount', ), ); function compareTotals($a, $b) { $aCode = $a['_code']; $bCode = $b['_code']; if (in_array($aCode, $b['after']) || in_array($bCode, $a['before'])) { $res = -1; } elseif (in_array($bCode, $a['after']) || in_array($aCode, $b['before'])) { $res = 1; } else { $res = 0; } return $res; } 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);
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Array ( [discount] => Array ( [class] => salesrule/quote_discount [after] => Array ( [0] => subtotal [1] => shipping ) [before] => Array ( [0] => grand_total ) [admin_renderer] => adminhtml/sales_order_create_totals_discount [renderer] => amrules/checkout_discount [_code] => discount ) [grand_total] => Array ( [class] => sales/quote_address_total_grand [after] => Array ( [0] => subtotal [1] => discount [3] => shipping ) [renderer] => tax/checkout_grandtotal [admin_renderer] => adminhtml/sales_order_create_totals_grandtotal [before] => Array ( ) [_code] => grand_total ) )

preferences:
292.06 ms | 408 KiB | 459 Q