在多維數組中,每個數組都有一個'order'字段。我需要改變這個值,如下所示:PHP號碼處理
0 -> 3
1 -> 2
2 -> 1
3 -> 0
4 -> 7
5 -> 6
6 -> 5
7 -> 4
8 -> 9
9 -> 8
等等
生病是如下
$c = 0;
foreach($data['images'] as $i)
{
//$i['order'] contains the original order value
$processed_imgs[$c]['file'] = $i['file'];
$processed_imgs[$c]['text'] = $i['text'];
$processed_imgs[$c]['order'] = 'X';
$c++;
}
$這樣做,同時通過遍歷數組I [ '秩序']包含原始訂單值(第一個代碼片段中的左列,從DB ASC出來),並且應該更改爲右列中的相應編號。
因此,基本上,需要將值改爲相反順序,同時以4個塊爲單位查看每組數字。我不知道最高順序號是多少,它會隨着新圖像的添加而增加。
使用上述foreach做這件事的最好方法是什麼?
這似乎回答你的問題非常好http://stackoverflow.com/questions/1316916/php-function-to-reorder-an-array – Prix 2010-08-02 19:17:15