如何将['访问'] [0]更改为名称:' location_1',['访问'] [1]:&# 39; location_2'等?
(
[visits] => Array
(
[0] => Array
(
[ID] => 24682
[Address] => 1234 Some Street, Houston TX 77777
)
[1] => Array
(
[ID] => 24685
[Address] => 2345 Any Street, Houston TX 77777
)
)
)
答案 0 :(得分:2)
循环并创建一个新数组:
foreach ($array["visits"] as $key => $value) {
$newArray["location_".($key+1)] = $value;
}
示例:
http://sandbox.onlinephpfunctions.com/code/b2bab7e7431f553faee32e028a0823b001214607