分类如何运作?
我正在查看我的一些旧工作,发现分类函数可以完美地满足我需要的某些用途,尽管我尝试了一种极其不同且冗长的方式。
所以我的问题是,asort在排序时如何保持关联?我认为数组可以按键或按值排序,是否有第三个排序基准?
I was having a look over some of my old work and saw that the asort function would have worked perfectly for some of the uses I needed, although I attempted an extremely different and longwinded way.
So my question is exactly, how does asort maintain association when sorting? I thought an array can be sorted by key, or by value, is there a third sorting pivot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“第三个枢轴”是内存/数组中的实际位置。
当对以下两个数组执行 foreach 时,您会清楚地看到这一点,这两个数组相同,但顺序不同:
对这两个数组执行默认排序将导致两种情况:
The "third pivot" is the actual location in memory/array.
You will see it clearly when doing a foreach on the following two arrays, which are the same, but have different order:
doing the default asort on those two arrays will result in both cases in:
来自手册:
因此,例如:
Asort
将仅按值升序排序,保持索引=>值关联。Arsort
是相同的,但是以 desc 方式。数组排序功能在这里。
基本函数仅按键或值排序,但有以下选项:
From the manual :
So, for example :
Asort
will just sort by value in ascending way keeping the index=>value association.Arsort
is the same but in desc way.The manual is pretty clear on Array sorting function here.
Basic function only sort by key or values but there are options: