@ 2014-09-26T17:36:05Z <?php
$configArray = array(
'grand_total' =>
array(
'after' =>
array(
0 => 'subtotal',
),
'before' =>
array(),
'_code' => 'grand_total',
),
'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',
),
);
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);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught TypeError: uasort(): Argument #2 ($callback) must be a valid callback, function "compareTotals" not found or invalid function name in /in/N92Hh:79
Stack trace:
#0 /in/N92Hh(79): uasort(Array, 'compareTotals')
#1 {main}
thrown in /in/N92Hh on line 79
Process exited with code 255 . Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: uasort() expects parameter 2 to be a valid callback, function 'compareTotals' not found or invalid function name in /in/N92Hh on line 79
Array
(
[grand_total] => Array
(
[after] => Array
(
[0] => subtotal
[1] => discount
[3] => shipping
)
[before] => Array
(
)
[_code] => grand_total
)
[discount] => Array
(
[after] => Array
(
[0] => subtotal
[1] => shipping
[2] => tax_subtotal
[3] => freeshipping
)
[before] => Array
(
[0] => grand_total
)
[_code] => discount
)
[tax_subtotal] => Array
(
[after] => Array
(
[0] => freeshipping
)
[before] => Array
(
[0] => tax
[1] => discount
[2] => grand_total
)
[_code] => tax_subtotal
)
)
Output for 5.2.5 - 5.2.17 Warning: uasort(): Invalid comparison function in /in/N92Hh on line 79
Array
(
[grand_total] => Array
(
[after] => Array
(
[0] => subtotal
[1] => discount
[3] => shipping
)
[before] => Array
(
)
[_code] => grand_total
)
[discount] => Array
(
[after] => Array
(
[0] => subtotal
[1] => shipping
[2] => tax_subtotal
[3] => freeshipping
)
[before] => Array
(
[0] => grand_total
)
[_code] => discount
)
[tax_subtotal] => Array
(
[after] => Array
(
[0] => freeshipping
)
[before] => Array
(
[0] => tax
[1] => discount
[2] => grand_total
)
[_code] => tax_subtotal
)
)
Output for 4.3.9 - 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.4 Warning: uasort(): Invalid comparison function. in /in/N92Hh on line 79
Array
(
[grand_total] => Array
(
[after] => Array
(
[0] => subtotal
[1] => discount
[3] => shipping
)
[before] => Array
(
)
[_code] => grand_total
)
[discount] => Array
(
[after] => Array
(
[0] => subtotal
[1] => shipping
[2] => tax_subtotal
[3] => freeshipping
)
[before] => Array
(
[0] => grand_total
)
[_code] => discount
)
[tax_subtotal] => Array
(
[after] => Array
(
[0] => freeshipping
)
[before] => Array
(
[0] => tax
[1] => discount
[2] => grand_total
)
[_code] => tax_subtotal
)
)
Output for 4.3.0 - 4.3.8 Array
(
[tax_subtotal] => Array
(
[after] => Array
(
[0] => freeshipping
)
[before] => Array
(
[0] => tax
[1] => discount
[2] => grand_total
)
[_code] => tax_subtotal
)
[discount] => Array
(
[after] => Array
(
[0] => subtotal
[1] => shipping
[2] => tax_subtotal
[3] => freeshipping
)
[before] => Array
(
[0] => grand_total
)
[_code] => discount
)
[grand_total] => Array
(
[after] => Array
(
[0] => subtotal
[1] => discount
[3] => shipping
)
[before] => Array
(
)
[_code] => grand_total
)
)
preferences:dark mode live preview
236.51 ms | 404 KiB | 326 Q