我基本上想用str_replace函數一個multidimenional陣列的所有值。我似乎無法解決如何爲多維數組做這件事。當數值是一個數組時,我會遇到一點困難,它似乎只是一個永無止境的循環。即時通訊新的PHP,所以emaples會有所幫助。多維數組的遞歸循環?
function _replace_amp($post = array(), $new_post = array())
{
foreach($post as $key => $value)
{
if (is_array($value))
{
unset($post[$key]);
$this->_replace_amp($post, $new_post);
}
else
{
// Replace :amp; for & as the & would split into different vars.
$new_post[$key] = str_replace(':amp;', '&', $value);
unset($post[$key]);
}
}
return $new_post;
}
感謝
讓我們看看你想出什麼用至今。 – amccormack 2011-05-22 14:54:24