php - 无法在 PHP 中排序多维数组

标签 php multidimensional-array

我有一个像这样的数组

array(40) {
  [134114]=>
  array(5) {
    ["yeniPoz"]=>
    int(3)
    ["yeniPuan"]=>
    int(108)
    ["isim"]=>
    string(16) "PERSON A"
    ["eskiPoz"]=>
    string(1) "1"
    ["eskiPuan"]=>
    string(3) "102"
  }
  [307674]=>
  array(5) {
    ["yeniPoz"]=>
    int(2)
    ["yeniPuan"]=>
    int(83)
    ["isim"]=>
    string(16) "PERSON B"
    ["eskiPoz"]=>
    string(1) "2"
    ["eskiPuan"]=>
    string(2) "75"
  }
  [263724]=>
  array(5) {
    ["yeniPoz"]=>
    int(10)
    ["yeniPuan"]=>
    int(65)
    ["isim"]=>
    string(9) "PERSON C"
    ["eskiPoz"]=>
    string(1) "3"
    ["eskiPuan"]=>
    string(2) "65"
  }

[209310]=>
  array(5) {
    ["yeniPoz"]=>
    int(1)
    ["yeniPuan"]=>
    int(72)
    ["isim"]=>
    string(29) "PERSON D"
    ["eskiPoz"]=>
    string(1) "4"
    ["eskiPuan"]=>
    string(2) "62"
  }
...

该数组是类的公共(public)元素 (public $datas) 。 我想用 yeniPuan 订购这个数组。

function orderManagersFunc($a, $b)
{
    return $b['yeniPuan'] - $a['yeniPuan'];
}

function orderManager()
{
    uasort($this->datas, "orderManagersFunc");
}

结果应该是这样的:

  1. A 人
  2. B 人
  3. D 人
  4. C 人

但是结果:

  1. A 人
  2. B 人
  3. C 人
  4. D 人

我认为是按 ["eskiPuan"] 订购的。

但我不知道,为什么?


如果您需要所有代码,您可以查看此存储库:https://github.com/erayalakese/GPRO-live-standings

GLS.class.php 文件中的类。我正在从index.php 调用函数

最佳答案

您只需替换以下行:

uasort($this->datas, "orderManagersFunc");

对于这个:

uasort($this->datas, array($this,"orderManagersFunc"));

因为这是指示您要按类中的方法排序的正确语法。

关于php - 无法在 PHP 中排序多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12482238/

相关文章:

php - 根据搜索值的部分匹配过滤多维数组

PHP语法问题: What does the question mark and colon mean?

php - 如果没有 ajax readystate() 中的 alert(),循环将无法工作

php - 如何为mysql数据库创建用户?

python - 在 Python 中迭代 3d 数组

php - 通过特定值的最大值从多维数组返回值

ruby - 将二维数组转换为哈希

c - 如何将 memchr 与二维数组一起使用?

php - 了解 gmtime 返回值

php - Mysql匹配为每个用户获取具有相似兴趣或相同性别的用户