Home > Backend Development > PHP Tutorial > php usort排序有关问题

php usort排序有关问题

WBOY
Release: 2016-06-13 10:36:02
Original
999 people have browsed it

php usort排序问题
echo '

';<br>function my_sort($a, $b)<br>   {<br>	   <br>   if ($a == $b) return 0;<br>var_dump($a);var_dump($b);echo '<br>';<br>   return ($a > $b) ? -1 : 1;<br>   }<br>	<br>$arr = array("Peter", "glenn","Cleveland","peter","cleveland", "Glenn");<br><br>usort($arr, "my_sort");<br><br>print_r ($arr);<br>  <br>1.我不明白 $a和$b都是字母,所以return ($a > $b) ? -1 : 1;  这个之间的比较,我不明白字母之间如果比大小<br>2.$a $b他们各种代表着什么<br><br><font color="#e78608">------解决方案--------------------</font><br>比如冒泡排序
Copy after login
PHP code
for($i=0; $i<count for if> $ar[$j]) {      swap($ar[$i], $ar[$j]);    }  }}<br><font color="#e78608">------解决方案--------------------</font><br><dl class="code">PHP code<pre class="brush:php;toolbar:false">$arr = array("Peter"=>array('a0'=>'a','a1'=>'3'),"glenn"=>array('b0'=>'a','b1'=>'1'),"Cleveland"=>array('c0'=>'a','c1'=>'2'));function my_sort($a, $b) {  return strcasecmp(end($a), end($b));}uasort($arr, "my_sort");print_r ($arr);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template