0
如何用新值替換多維數組內的字符串/單詞?我沒有鑰匙,只知道乾草堆和針。如何替換多維數組中的字符串?
說我有一個多維數組,$submenu_arr
,(不知道有多少維度)。
我想在其中一個數組中找到一個值,並用新值替換它。
其實翻譯。
像:
recursive_arr_translation('Article', $submenu_arr, 'Artigo');//"Artigo" is a Portuguese word for "Article".
我已經試過這一點,但不工作:
function in_array_r($needle, $haystack, $new_value) {
$found = false;
foreach ($haystack as $key=>$value) {
if ($value === $needle) {
$found = true;
$haystack[$key] = $new_value;
return true;
} elseif (is_array($value)) {
$found = in_array_r($needle, $haystack[$key], $new_value);
if($found) {
return true;
}
}
}
return $found;
}
in_array_r('Article', $submenu, 'Artigo');
in_array_r('Location', $submenu, 'Localização');
編輯:是工作,但不知何故,我不明白這一點的工作,我想翻譯WordPress子菜單詞。
'array_walk_recursive' ...?! – deceze 2014-09-26 13:32:46
array_walk_recursive對我而言是新的 – 2014-09-26 13:35:07
http://php.net/array_walk_recursive – deceze 2014-09-26 13:35:44