I have a multidimensional array in PHP that appears as:
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
)
)
I would like to loop through this array and append the same parameter to both url keys. I tried doing this through a function with a double foreach loop and was able to append the parameter successfully, but I'm having trouble returning an array with the updated values.
Here is what I've tried:
Call
$array = append_field($array, 'url', '?parameter=test');
Function
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;
}