在PHP数组排序功能 [英] Array sort function in PHP
本文介绍了在PHP数组排序功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了一个 myArr,该=(2007-4-1,月,月)
。是否有一个排序功能通过字母来另有性质一个月序列阵列成员排序。
I defined a myArr = ("Apr","Mar","May")
. Is there a sorting function to sort the array members by nature month sequence otherwise by alphabet.
阵列成员变量可以在运行时被改变。
The array members variables can will be changed at runtime.
我希望它的输出随后三月,四月,五月使用foreach循环。
I want it output followed Mar, Apr, May using foreach loop.
推荐答案
您可以使用usort(),并创建自己的函数来比较个月。
You could use usort() and create your own function to compare months.
function monthCompare($a, $b)
{
$months = array('jan' => 1, 'feb' => 2..._);
if($a == $b)
{
return 0;
}
return ($months[$a] > $months[$b]) ? 1 : -1;
}
这篇关于在PHP数组排序功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文