我在PHP多维数组显示为:追加值到多维数组PHP
Array
(
[0] => Array
(
[background] => https://example.com/image.jpg
[description] => Example text
[url] => https://example.com
)
[1] => Array
(
[background] => https://example.com/image.jpg
[description] => Example text
[url] => https://example.com
)
)
我想通过这个数组循环和相同的参数附加到两个url
密钥。我试着通过一个带有双foreach循环的函数来做到这一点,并且能够成功追加参数,但是我无法返回具有更新值的数组。
这里是我试过:
呼叫
$array = append_field($array, 'url', '?parameter=test');
功能
function append_field($array, $field, $parameter)
{
foreach ($array as $inner_array) :
foreach ($inner_array as $key => $append) :
if ($key == $field) :
$append .= $parameter;
endif;
endforeach;
endforeach;
return $array;
}