[英]XML node and values reversed using SimpleXMLElement and array_walk()
[英]Using array_walk to alter array values
這是我要在一組數組項上調用的函數:
function do_this_stuff( &$key ) {
$lookups = array(
'this' => 'that'
);
if (array_key_exists($key, $lookups)) {
return $lookups[$key];
} else {
return ucwords(str_replace("_", " ", $key));
}
}
並對其進行調用:
array_walk($data[$set][0], 'do_this_stuff');
如果$lookups
數組中的任何內容位於array walk參數之一的數組中,我想替換其內容。 do_this_stuff
函數有效,但是我嘗試過的所有操作do_this_stuff
導致實際輸入數組值的更新。
您需要將更新后的值分配回$key
,而不返回它。
function do_this_stuff( &$key ) {
$lookups = array(
'this' => 'that'
);
if (array_key_exists($key, $lookups)) {
$key = $lookups[$key];
} else {
$key = ucwords(str_replace("_", " ", $key));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.