私は配列を持っています:
$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ループを持っており、毎回配列を単純に並べ替える簡単な方法があれば、それは本当に役に立ちます。