正在寻找php脚本,将电话号码(xxx xxx xxxx)按单独的行进行排序
我正在寻找php数组脚本,这样我就可以在单独的行中编写电话号码列表,如 第一线xxx-xxx-0001 第二行中的xxx-xxx-0002 第三行中的xxx-xxx-0003 在我的网站上正在寻找php脚本,将电话号码(xxx xxx xxxx)按单独的行进行排序,php,arrays,Php,Arrays,我正在寻找php数组脚本,这样我就可以在单独的行中编写电话号码列表,如 第一线xxx-xxx-0001 第二行中的xxx-xxx-0002 第三行中的xxx-xxx-0003 在我的网站上 <!DOCTYPE html> <html> <body> <?php $numbers = array(4, 6, 2, 22, 11); sort($numbers); $arrlength = count($numbers); for($x = 0; $x
<!DOCTYPE html>
<html>
<body>
<?php
$numbers = array(4, 6, 2, 22, 11);
sort($numbers);
$arrlength = count($numbers);
for($x = 0; $x < $arrlength; $x++) {
echo $numbers[$x];
echo "<br>";
}
?>
</body>
</html>
我正在尝试添加电话格式xxx xxx xxxx而不是号码,但它不起作用
<!DOCTYPE html>
<html>
<body>
<?php
$numbers = array(416-224-0001,416-224-0002,416-224-0003);
sort($numbers);
$arrlength = count($numbers);
for($x = 0; $x < $arrlength; $x++) {
echo $numbers[$x];
echo "<br>";
}
?>
</body>
</html>
这就是我所尝试的,如果我做错了什么,请告诉我假设您想纯粹根据连字符后的最后4位进行排序:
function cmp($a, $b) {
if ($a == $b) {//ptobably wont apply here
return 0;
}
$explodedA = explode('-', $a);
$explodedB = explode('-', $b);
$lastBitA = $explodedA[count($explodedA) - 1];//get the last section for the compare
$lastBitB = $explodedB[count($explodedB) - 1];
if ($lastBitA == $lastBitB) {
return ($a < $b) ? -1 : 1;
}
return ($lastBitA < $lastBitB) ? -1 : 1;
}
$numbers = array('777-999-0002','416-224-0003','416-224-0001','776-244-0008');
usort($numbers, "cmp");
print_r($numbers);
非常感谢您的帮助,很抱歉由于某些原因仍然无法工作,请您再为我检查一次。。。谢谢
Array
(
[0] => 416-224-0001
[1] => 777-999-0002
[2] => 416-224-0003
[3] => 776-244-0008
)