還有一個數組,如何使數組的key與id相同?PHP foreach array key
Array
(
[0] => Array
(
[id] => 1
[title] => Phones
[parent] => 0
)
[1] => Array
(
[id] => 2
[title] => Apple
[parent] => 1
)
[2] => Array
(
[id] => 5
[title] => Samsung
[parent] => 1
)
)
我試過這樣做,但事實證明相反,id變得與數組鍵相同。它應該是相反的。
foreach ($statement as $key => $value) {
$statement[$key]['id'] = $key;
}
參見:http://stackoverflow.com/q/1494953/3933332 – Rizier123