PHP offers several ways to mutate iterable data.
Use array_map() with the union operator to append a new elements to each row. Demo
$feedId = 42;
$rss->items = array_map(
fn($item) => $item + ['feed_id' => $feedId],
$rss->items
);
var_export($rss);
Telling a foreach() loop to modify the original array instead of a copy of the input array is done by prepending an ampersand to the row variable declaration. Demo
$feedId = 42;
foreach ($rss->items as &$item) {
$item['feed_id'] = $feedId;
}
var_export($rss);
Iterate a copy of the input array, but then access the keys and use them to affect the original array. (Demo)
$feedId = 42;
foreach ($rss->items as $key => $item) {
$rss->items[$key]['feed_id'] = $feedId;
}
var_export($rss);
As a divergence of the proposed scenario, but topically related, if the input is an array of objects, a foreach() will iterate the original array (not a copy) without needing a prepended ampersand. Demo
$items = [
(object) ['foo' => 'bar1'],
(object) ['foo' => 'bar2'],
(object) ['foo' => 'bar3'],
];
$feedId = 42;
foreach ($items as $obj) {
$obj->feed_id = $feedId;
}
var_export($items);