Source Code:
(back to article)
<?php $names = ["John", "Adam", "Jack", "Jenny", "Bob"]; usort($names, function ($a, $b) { if ($a[0] == "J" && $b[0] != "J") { return -1; } elseif ($a[0] != "J" && $b[0] == "J") { return 1; } else { return strcmp($a, $b); } }); print_r($names);
Result:
Report an issue