Phpusort sorting problems

Source: Internet
Author: User
Echo & lt; pre & gt; functionmy_sort ($ a, $ B) & nbsp ;{& nbsp; & nbsp; if ($ a $ B) return0; var_dump ($ a); var_dump ($ B); echo & lt; br & gt; & nbsp; return ($ a & gt; $ B) php usort sorting problem
Echo'
';
Function my_sort ($ a, $ B)
{

If ($ a = $ B) return 0;
Var_dump ($ a); var_dump ($ B); echo'
';
Return ($ a> $ B )? -1: 1;
}

$ Arr = array ("Peter", "glenn", "Cleveland", "peter", "cleveland", "Glenn ");

Usort ($ arr, "my_sort ");

Print_r ($ arr );

1. I don't understand that $ a and $ B are both letters, so return ($ a> $ B )? -1: 1; I do not understand the ratio of the ratio between letters.
2. $ a $ B What do they represent?

------ Solution --------------------
For example, bubble sorting
PHP code
For ($ I = 0; $ I
   
    
$ Ar [$ j]) {swap ($ ar [$ I], $ ar [$ j]) ;}}
    
------ Solution --------------------
PHP code
$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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.