我用过
unset($quotes_array[0]['methods'][0]);
$quotes_array[0]['methods'] = array_values($quotes_array[0]['methods']);
删除数组的第一个元素,但使用数组的选择表单不再正确响应用户选择的单选按钮。原始数组如下所示:
Array
(
[0] => Array
(
[id] => advshipper
[methods] => Array
(
[0] => Array
(
[id] => 1-0-0
[title] => Trade Shipping
[cost] => 20
[icon] =>
[shipping_ts] =>
[quote_i] => 0
)
[1] => Array
(
[id] => 2-0-0
[title] => 1-2 working days
[cost] => 3.2916666666667
[icon] =>
[shipping_ts] =>
[quote_i] => 1
)
[2] => Array
(
[id] => 4-0-0
[title] => 2-3 working days
[cost] => 2.4916666666667
[icon] =>
[shipping_ts] =>
[quote_i] => 2
)
[3] => Array
(
[id] => 8-0-0
[title] => Click & Collect
[cost] => 0
[icon] =>
[shipping_ts] =>
[quote_i] => 3
)
)
[module] => Shipping
[tax] => 20
)
)
修改后的数组如下所示:
Array
(
[0] => Array
(
[id] => advshipper
[methods] => Array
(
[0] => Array
(
[id] => 2-0-0
[title] => 1-2 working days
[cost] => 3.2916666666667
[icon] =>
[shipping_ts] =>
[quote_i] => 1
)
[1] => Array
(
[id] => 4-0-0
[title] => 2-3 working days
[cost] => 2.4916666666667
[icon] =>
[shipping_ts] =>
[quote_i] => 2
)
[2] => Array
(
[id] => 8-0-0
[title] => Click & Collect
[cost] => 0
[icon] =>
[shipping_ts] =>
[quote_i] => 3
)
)
[module] => Shipping
[tax] => 20
)
)
我怀疑问题是由于在修改后的数组中,[quote_i] 现在从 1 开始,而不是原始数组中的 0。所以我有 [quote_i] 为 1, 2 然后 3 但它应该是 0, 1, 然后 2。
我尝试使用 array_walk 来纠正这个问题,但没有成功。
关于解决此问题的任何建议?