3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [ 0 => [ 'period' => '2017/2018', 'product' => 'AM', 'quantity_1' => 20, 'quantity' => 25, ], 1 => [ 'period' => '2018/2019', 'product' => 'AM', 'quantity_1' => 12, 'quantity' => 19, ], 2 => [ 'period' => '2017/2018', 'product' => 'DC', 'quantity_1' => 20, 'quantity' => 25, ], 3 => [ 'period' => '2018/2019', 'product' => 'DC', 'quantity_1' => 8, 'quantity' => 10, ] ]; $temp = []; foreach ($a as $x){ $temp[$x['product']][$x['period']] = $x; } print_r($temp); $result = []; foreach ($temp as $key => $res){ $result[] = [ 'product' => $key, 'quantity_1' => $res['2018/2019']['quantity_1'] / $res['2017/2018']['quantity_1'], 'quantity_2' => $res['2018/2019']['quantity'] / $res['2017/2018']['quantity'], ]; } print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [AM] => Array ( [2017/2018] => Array ( [period] => 2017/2018 [product] => AM [quantity_1] => 20 [quantity] => 25 ) [2018/2019] => Array ( [period] => 2018/2019 [product] => AM [quantity_1] => 12 [quantity] => 19 ) ) [DC] => Array ( [2017/2018] => Array ( [period] => 2017/2018 [product] => DC [quantity_1] => 20 [quantity] => 25 ) [2018/2019] => Array ( [period] => 2018/2019 [product] => DC [quantity_1] => 8 [quantity] => 10 ) ) ) Array ( [0] => Array ( [product] => AM [quantity_1] => 0.6 [quantity_2] => 0.76 ) [1] => Array ( [product] => DC [quantity_1] => 0.4 [quantity_2] => 0.4 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.94 ms | 409 KiB | 5 Q