3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array('product_code' => 'battle-for-zendikar-token-1', 'product' => 'battle-for-zendikar-token-1'), array('product_code' => 'battle-for-zendikar-token-2', 'product' => 'battle-for-zendikar-token-2'), array('product_code' => 'battle-for-zendikar-token-3', 'product' => 'battle-for-zendikar-token-3'), array('product_code' => 'battle-for-zendikar-token-4', 'product' => 'battle-for-zendikar-token-4'), array('product_code' => 'battle-for-zendikar-token-5', 'product' => 'battle-for-zendikar-token-5'), array('product_code' => 'battle-for-zendikar-token-6', 'product' => 'battle-for-zendikar-token-6'), array('product_code' => 'battle-for-zendikar-token-7', 'product' => 'battle-for-zendikar-token-7'), array('product_code' => 'battle-for-zendikar-token-8', 'product' => 'battle-for-zendikar-token-8'), array('product_code' => 'battle-for-zendikar-token-9', 'product' => 'battle-for-zendikar-token-9'), array('product_code' => 'battle-for-zendikar-token-10', 'product' => 'battle-for-zendikar-token-10'), array('product_code' => 'battle-for-zendikar-token-11', 'product' => 'battle-for-zendikar-token-11'), array('product_code' => 'battle-for-zendikar-token-12', 'product' => 'battle-for-zendikar-token-12'), array('product_code' => 'battle-for-zendikar-token-13', 'product' => 'battle-for-zendikar-token-13'), array('product_code' => 'battle-for-zendikar-token-14', 'product' => 'battle-for-zendikar-token-14'), array('product_code' => 'battle-for-zendikar-1', 'product' => 'battle-for-zendikar-1'), array('product_code' => 'battle-for-zendikar-2', 'product' => 'battle-for-zendikar-2'), array('product_code' => 'battle-for-zendikar-3', 'product' => 'battle-for-zendikar-3'), array('product_code' => 'battle-for-zendikar-4', 'product' => 'battle-for-zendikar-4'), array('product_code' => 'battle-for-zendikar-5', 'product' => 'battle-for-zendikar-5'), array('product_code' => 'battle-for-zendikar-6', 'product' => 'battle-for-zendikar-6'), array('product_code' => 'battle-for-zendikar-7', 'product' => 'battle-for-zendikar-7'), array('product_code' => 'battle-for-zendikar-8', 'product' => 'battle-for-zendikar-8'), array('product_code' => 'battle-for-zendikar-9', 'product' => 'battle-for-zendikar-9'), array('product_code' => 'battle-for-zendikar-10', 'product' => 'battle-for-zendikar-10'), array('product_code' => 'battle-for-zendikar-11', 'product' => 'battle-for-zendikar-11'), array('product_code' => 'battle-for-zendikar-12', 'product' => 'battle-for-zendikar-12'), array('product_code' => 'battle-for-zendikar-13', 'product' => 'battle-for-zendikar-13'), array('product_code' => 'battle-for-zendikar-14', 'product' => 'battle-for-zendikar-14'), array('product_code' => 'battle-for-zendikar-15', 'product' => 'battle-for-zendikar-15'), array('product_code' => 'battle-for-zendikar-16', 'product' => 'battle-for-zendikar-16'), array('product_code' => 'battle-for-zendikar-17', 'product' => 'battle-for-zendikar-17'), array('product_code' => 'battle-for-zendikar-18', 'product' => 'battle-for-zendikar-18'), array('product_code' => 'battle-for-zendikar-19', 'product' => 'battle-for-zendikar-19'), array('product_code' => 'battle-for-zendikar-20', 'product' => 'battle-for-zendikar-20') ); function sortProducts($products) { $_sorted = array(); $_unsortable = array(); $_numbers = array(); if (is_array($products) && count($products)) { foreach ($products as $product) { preg_match('/[0-9]+$/', $product['product_code'], $_numbers); $_number = $_numbers[0]; $initial_code_part = substr($product['product_code'],0,strrpos($product['product_code'],$_number)); if (!empty($_number)) { $_sorted[$initial_code_part][$_number] = $product; continue; } $_unsortable[$product['product_code']] = $product; } if (count($_sorted) > 1) { $_newSorteddata = array(); foreach ($_sorted as $_sortKey => $_sortedData) { if (!count($_newSorteddata)) { $_newSortedData = $_sortedData; } else { $params = $_sorteddata; array_shift($params,$_newSortedData); $_newSortedData = call_user_func_array('array_push',$params); } } $_sorted = $_newSortedData; } ksort($_sorted); ksort($_unsortable); if (!count($_sorted)) { return $_unsortable; } return $_sorted + $_unsortable; } return $products; } var_dump(sortProducts($arr));
Output for git.master, git.master_jit, rfc.property-hooks
array(20) { [1]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-1" ["product"]=> string(21) "battle-for-zendikar-1" } [2]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-2" ["product"]=> string(21) "battle-for-zendikar-2" } [3]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-3" ["product"]=> string(21) "battle-for-zendikar-3" } [4]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-4" ["product"]=> string(21) "battle-for-zendikar-4" } [5]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-5" ["product"]=> string(21) "battle-for-zendikar-5" } [6]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-6" ["product"]=> string(21) "battle-for-zendikar-6" } [7]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-7" ["product"]=> string(21) "battle-for-zendikar-7" } [8]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-8" ["product"]=> string(21) "battle-for-zendikar-8" } [9]=> array(2) { ["product_code"]=> string(21) "battle-for-zendikar-9" ["product"]=> string(21) "battle-for-zendikar-9" } [10]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-10" ["product"]=> string(22) "battle-for-zendikar-10" } [11]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-11" ["product"]=> string(22) "battle-for-zendikar-11" } [12]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-12" ["product"]=> string(22) "battle-for-zendikar-12" } [13]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-13" ["product"]=> string(22) "battle-for-zendikar-13" } [14]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-14" ["product"]=> string(22) "battle-for-zendikar-14" } [15]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-15" ["product"]=> string(22) "battle-for-zendikar-15" } [16]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-16" ["product"]=> string(22) "battle-for-zendikar-16" } [17]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-17" ["product"]=> string(22) "battle-for-zendikar-17" } [18]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-18" ["product"]=> string(22) "battle-for-zendikar-18" } [19]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-19" ["product"]=> string(22) "battle-for-zendikar-19" } [20]=> array(2) { ["product_code"]=> string(22) "battle-for-zendikar-20" ["product"]=> string(22) "battle-for-zendikar-20" } }

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:
63.66 ms | 409 KiB | 8 Q