我使用下面的代碼刪除陣列,但我覺得有一個問題如何更改陣列特別關鍵數字在PHP
How do I delete a specific array in php
array(2) {
[7]=>array(3) {
["title"]=>string(3) "ads"
["number"]=>int(3)
[1]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2017/08/120-3.jpg"
["expire"]=>string(10) "2017/03/10"
}
[2]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2016/09/240.jpg"
["expire"]=>string(10) "2016/10/20"
}
[3]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2016/10/300.jpg"
["expire"]=>string(10) "2016/12/28"
}
}
["_multiwidget"]=>int(1)
}
運行後:
array(2) {
[7]=>array(2) {
["title"]=>string(3) "ads"
["number"]=>int(2)
[1]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2017/08/120-3.jpg"
["expire"]=>string(10) "2017/03/10"
}
[3]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2016/10/300.jpg"
["expire"]=>string(10) "2016/12/28"
}
}
["_multiwidget"]=>int(1)
}
但我想稍後改變刪除如下(關鍵從[3]改爲[2]):
array(2) {
[7]=>array(2) {
["title"]=>string(3) "ads"
["number"]=>int(2)
[1]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2017/08/120-3.jpg"
["expire"]=>string(10) "2017/03/10"
}
[2]=>array(2) {
["address-image"]=>string(63) "http://localhost/wordpress/wp-content/uploads/2016/10/300.jpg"
["expire"]=>string(10) "2016/12/28"
}
}
["_multiwidget"]=>int(1)
}
對不起,我的英語不是很好
謝謝
爲什麼關鍵幾乎不相關。使用'foreach'和誰在乎 – RiggsFolly
如果你想將索引從'[3]'更改爲'[2]',使用'array_values'函數。它重新索引並返回數組。 – Perumal