Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 难以对多维关联数组进行排序_Php_Arrays_Sorting_Associative Array - Fatal编程技术网

Php 难以对多维关联数组进行排序

Php 难以对多维关联数组进行排序,php,arrays,sorting,associative-array,Php,Arrays,Sorting,Associative Array,我花了很长时间浏览论坛,但就是无法让它发挥作用 我有一个多维的关联数组(在类中)。声明如下: protected $ISSNLookup = array(); 在函数中,我说(从另一个数据源填充数组): 如果我随后使用以下命令显示数组内容: foreach($this->ISSNLookup as $key => $value) { echo $key . ' (' . $value['journal'] . '): ' . $value['number'] . '</b

我花了很长时间浏览论坛,但就是无法让它发挥作用

我有一个多维的关联数组(在类中)。声明如下:

protected $ISSNLookup = array();
在函数中,我说(从另一个数据源填充数组):

如果我随后使用以下命令显示数组内容:

foreach($this->ISSNLookup as $key => $value) {
  echo $key . ' (' . $value['journal'] . '): ' . $value['number'] . '</br>';
}
如果我现在排序,使用

usort($this->ISSNLookup, array($this, 'ISSNLookupJournalNameSort'));
使用函数(比较值):

然后再次显示(使用与上面相同的代码),我得到:

排序工作正常(即名称已排序-但9字符ID发生了什么变化?它似乎已恢复为计数器


感谢您的帮助。

答案很简单,请使用
uasort

uasort
-使用用户定义的比较函数对数组进行排序,并维护索引关联


有关排序方法的其他信息。

谢谢-让我试试……感谢您的快速回复。请随意接受答案。同时接受其他问题的答案,这会给您一些分数,并帮助其他人。
0924-669X (Applied Intelligence): 3

1943-068X (IEEE Transactions on Computational Intelligence and AI in Games): 6

1000-9000 (Journal of Computer Science and Technology): 1

0377-2217 (European Journal of Operational Research): 8

0020-7721 (International Journal of Systems Science): 1

1619-4500 (4OR - A Quarterly Journal of Operations Research): 2

0160-5682 (Journal of the Operational Research Society): 11
usort($this->ISSNLookup, array($this, 'ISSNLookupJournalNameSort'));
function ISSNLookupJournalNameSort($a, $b) {
    return strcmp($a['journal'], $b['journal']);
}
0 (4OR - A Quarterly Journal of Operations Research): 2

1 (Advances in Econometrics): 1

2 (Annals of Operations Research): 3

3 (Applied Intelligence): 3

4 (Applied Soft Computing): 3

5 (Artificial Life): 1
uasort($this->ISSNLookup, array($this, 'ISSNLookupJournalNameSort'));