欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 数组排序函数 array_multisort与uasort的区别

程序员文章站 2022-05-17 17:58:17
...
  1. function my_sort($a, $b)
  2. {
  3. if ($a == $b) return 0;
  4. return ($a > $b) ? -1 : 1;
  5. }
  6. $people = array("Swanson" => "Joe",
  7. "Griffin" => "Peter", "Quagmire" => "Glenn",
  8. "swanson" => "joe", "griffin" => "peter",
  9. "quagmire" => "glenn");
  10. uasort($people, "my_sort");
  11. print_r ($people);
  12. ?>
复制代码

输出结果: Array ( [griffin] => peter [swanson] => joe [quagmire] => glenn [Griffin] => Peter [Swanson] => Joe [Quagmire] => Glenn )

>>> 更多内容,请查看 php数组排序方法大全