3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSuitValue($card) { $result = 0; switch($card[1]) { case 'C' : $result *= 10; break; case 'H' : $result *= 100; break; case 'D' : $result *= 1000; break; default: $result *= 1; } return $result; } function getValue($card) { $result = 0; switch($card[0]) { case 'A' : $result += 1; break; case 'J' : $result += 11; break; case 'Q' : $result += 12; break; case 'K' : $result += 13; break; default: $result += (int)$card[0]; } return $result; } function isGreat($card1, $card2) { $val1 = getValue($card1); $val2 = getValue($card2); if ($val1 > $val2) { return true; } elseif ($val1 === $val2) { if (getSuitValue($card1) > getSuitValue($card2)) { return true; } } return false; } function mySort($arr) { for ($i = 1; $i < count($arr); $i++) { $x = $arr[$i]; for ($j = $i - 1; $j >= 0 && isGreat($arr[$j], $x); $j--) { $arr[$j + 1] = $arr[$j]; } // на оставшееся после сдвига место, ставим $a[$i] $arr[$j + 1] = $x; } return $arr; } function sort_cards($cards) { $array = explode(', ', $cards); $resultArr = mySort($array); return implode(', ', $resultArr); } echo sort_cards('1C, 5S, 4D'), PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
1C, 4D, 5S

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:
49.88 ms | 401 KiB | 8 Q