3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sortByDefault(array &$domains, $default='com') { $sort = array($default, 'net', 'org', 'us', 'biz', 'info'); uasort($domains, function($a, $b) use ($sort) { foreach ($sort as $tld) { if ($a['tld'] === $tld) { return -1; } elseif ($b['tld'] === $tld) { return 1; } } return strcmp($a['tld'], $b['tld']); }); return $domains; } $domains = array('google.com', 'google.net', 'google.org', 'google.us', 'google.biz', 'google.info'); // Format these into arrays so that this shitty function works. $domains = array_map(function($d) { list($name, $tld) = explode('.', $d); return array('name' => $name, 'tld' => $tld); }, $domains); var_dump(sortByDefault($domains, 'biz'));

preferences:
47.37 ms | 402 KiB | 5 Q