1
我有關聯期多維陣列保持計數鍵
Array
(
[1] => Array
(
[Chapter] => Name 1
[Section] => Array
(
[1] => Section name 1
[2] => Section name 2
[3] => Section name 3
)
)
[2] => Array
(
[Chapter] => Name 2
[Section] => Array
(
[1] => Section name 4
[2] => Section name 5
)
)
)
我想繼續鍵數字計數爲第名稱1,第名稱2,節名稱3,節名稱4,段名5.陣列的按鍵將匹配部分的名稱 所以它會看起來像這樣
Array
(
[1] => Array
(
[Chapter] => Name 1
[Section] => Array
(
[1] => Section name 1
[2] => Section name 2
[3] => Section name 3
)
)
[2] => Array
(
[Chapter] => Name 2
[Section] => Array
(
[4] => Section name 4
[5] => Section name 5
)
)
)
我試圖做
$count = 0;
foreach ($sections as $key => $value) {
foreach ($value['Section'] as $k => $val) {
$count ++;
$value['Section'][$count] = $value['Section'][$k];
unset($value['Section'][$k]);
}
}
,但它仍然指望從1
路過你有兩個使用&$值。 –
什麼是$值? – user45669
做一個參考而不是一個副本,只有你的更改會在下面的答案中發生 –