- microtime: documentation ( source)
- preg_replace: documentation ( source)
- usort: documentation ( source)
<?php
$telefones = [
'(11) 3333-4353',
'(11) 98000-2222',
'(11) 3027-5555',
'(11) 97000-0333',
'(12) 99999-9999',
'(12) 88888-8888',
'(13) 11111-1111'
];
$inicio = microtime(true);
function sortNumber($a, $b) {
$a = preg_replace('/\D/', '', $a);
$b = preg_replace('/\D/', '', $b);
return ($a > $b) ? -1 : 1;
}
for($i = 0; $i < 50000; $i++){
usort($telefones, 'sortNumber');
}
echo 'Bruno Rigolon:' . (microtime(true) - $inicio) . "\n";
This script was stopped while abusing our resources