【发布时间】:2011-08-30 15:05:12
【问题描述】:
我基本上想使用 str_replace 多维数组的所有值。我似乎无法弄清楚如何为多维数组执行此操作。当值是一个数组时,我有点卡住了,它似乎处于一个永无止境的循环中。我是 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;
}
谢谢
【问题讨论】:
-
向我们展示您目前的想法。
标签: php loops recursion multidimensional-array