<?php
$ar = array(
"aa ¦aad ¦123 ¦afas",
"aa ¦aad ¦13 ¦afas",
"aa ¦aad ¦23 ¦afas",
"aa ¦aad ¦12 ¦afas",
"aa ¦aad ¦1 ¦afas",
"aa ¦aad ¦2 ¦afas"
);
function cmd($a,$b) {
$a1 = explode(" ¦",$a);
$b1 = explode(" ¦",$b);
if($a1[2] == $b1[2])
return 0;
return ($a1[2]>$b1[2])?1:-1;
}
usort($ar,cmd);
?>
结果
Array
(
[0] => aa ¦aad ¦1 ¦afas
[1] => aa ¦aad ¦2 ¦afas
[2] => aa ¦aad ¦12 ¦afas
[3] => aa ¦aad ¦13 ¦afas
[4] => aa ¦aad ¦23 ¦afas
[5] => aa ¦aad ¦123 ¦afas
)