php foreach修改数组长度,PHP:数组修改超出了foreach循环的范围

如何将新的键/值对添加到嵌套的foreach循环内的现有数组中,并使该对保持在循环范围之外?

include('magpierss/rss_fetch.inc');

/*

one, two, skip a few...

$urls is an associative array with

database indices as keys and

URLs as values

*/

foreach ($urls as $url_hsh)

{

$feed_id = $url_hsh[0];

$url = $url_hsh[1];

echo $feed_id . "
" . $url . "
"; // works as expected

$rss = fetch_rss($url); // from 'magpierss/rss_fetch.inc' above

foreach ($rss->items as $item)

{

$item['feed_id'] = $feed_id;

echo $item['feed_id'] . "
"; // works as expected

}

foreach ($rss->items as $item)

{

echo $item['feed_id'] . "
"; // nuthin.....

}

}

?>

谢谢

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值