我有一個這樣的數組:在multidimensionnal陣列替換字符串
Array
(
[0] => Array
(
[objectid] => 197
[adresse] => D554
[city] => NEW-YORK
[lat] => 12,545484654687
[long] => 12,545484654687
)
[1] => Array
(
[objectid] => 198
[adresse] => D556
[city] => WASHINGTON
[lat] => 12,545484654687
[long] => 12,545484654687
)
...
...
)
我想要像0,1,2標識符改變城市名稱...
其實,我做到了這一點通過此代碼:
foreach ($big_array as $key => $value){
if ($value['city'] == "NEW-YORK"){
$big_array[$key] = str_replace("NEW-YORK", 0, $value);
} elseif($value['city'] == "WASHINGTON") {
$big_array[$key] = str_replace("WASHINGTON", 1, $value);
} etc...
}
我不認爲這是做這件事的最佳方式,我有一個巨大的城市名單。 是否有可能定義像的數組:
$replacements = array(
"NEW-YORK" => 0,
"WASHINGTON" => 1,
etc...
)
和使用函數來簡單地進行變化?
不應該它是'if($ key ['city'] ==「NEW-YORK」){'? –
尋找'php array_merge' – Lekhnath