3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 'itemA' => [ 'product_id' => 1, 'category_id' => 1, ], 'itemB' => [ 'product_id' => 2, 'category_id' => 2, ], 'itemC' => [ 'product_id' => 3, 'category_id' => 1, ], 'itemE' => [ 'product_id' => 4, 'category_id' => 1, ], 'itemD' => [ 'product_id' => 5, 'category_id' => 2, ], ]; uasort($arr, function ($a, $b) { if ($a['category_id'] == $b['category_id']) { return $a['product_id'] - $b['product_id']; } return $a['category_id'] < $b['category_id'] ? -1 : 1; }); var_dump($arr);
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { ["itemA"]=> array(2) { ["product_id"]=> int(1) ["category_id"]=> int(1) } ["itemC"]=> array(2) { ["product_id"]=> int(3) ["category_id"]=> int(1) } ["itemE"]=> array(2) { ["product_id"]=> int(4) ["category_id"]=> int(1) } ["itemB"]=> array(2) { ["product_id"]=> int(2) ["category_id"]=> int(2) } ["itemD"]=> array(2) { ["product_id"]=> int(5) ["category_id"]=> int(2) } }

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:
143.13 ms | 406 KiB | 5 Q