对不起我的标题。我只是不知道怎么问这个。长话短说,我只需要替换数组的某个部分。假设我们有这个数组:
Array
(
[0] => Array
(
[restaurant_id] => 1236
[new_lat] => 76
[new_long] => 86
[date_updated] => 2013-11-15 17:20:58
)
[1] => Array
(
[restaurant_id] => 1247
[new_lat] => 6
[new_long] => 5
[date_updated] => 2013-11-15 17:20:58
)
[2] => Array
(
[restaurant_id] => 7456
[new_lat] => 21
[new_long] => 12
[date_updated] => 2013-11-15 17:20:58
)
)
现在我需要用这个替换索引 2:
Array(
[2] => Array
(
[restaurant_id] => 1236
[new_lat] => 2
[new_long] => 1
[date_updated] => 2013-11-15 17:20:58
)
)
如果我发现有一个现有的 restaurant_id,我需要更换。如果有。更新该行。我没有添加新数组。
我有一个想法,但我不知道该怎么做。我的想法是:
反序列化数组(因为我的数组是序列化形式)
找到目标索引。如果找到删除该索引并将我的新索引添加到数组的底部,然后再次序列化它。如果未找到,则仅在数组底部添加并序列化。
我只是不知道我是否删除了索引。如果索引会自动移动。意味着如果我删除索引 2,索引 3 将成为索引 2,而我的新数组是索引 3。
好的,这就是所有的家伙。谢谢。