我有一个数组:重新安排PHP关联数组
$example = array();
$example ['one'] = array('first' => 'blue',
'second' => 'red');
$example ['two'] = array('third' => 'purple',
'fourth' => 'green');
$example ['three'] = array('fifth' => 'orange',
'sixth' => 'white');
基于某些输入到函数中,我需要改变示例数组的顺序foreach循环处理我的输出之前:
switch($type)
case 'a':
//arrange the example array as one, two three
break;
case 'b':
//arrange the example array as two, one, three
break;
case 'c':
//arrange the example array in some other arbitrary manner
break;
foreach($example as $value){
echo $value;
}
有没有简单的方法来做到这一点,而无需重新设计我所有的代码?我有一个相当深入的foreach循环来处理,如果有简单的方法可以简单地重新排序数组,每次都会非常有用。
你的“任意数组排序?”的目的是什么?你只是试图随机化订单?或者,你是否特别想以参数化的方式转移项目? – user1477388 2013-02-26 21:23:37
我想问题的关键是我需要对它们进行排序,并且不会落入任何现成的排序标准,如字母或数字......我需要将它按照我如何分类进行排序。 – absentx 2013-02-26 21:55:24