dongwen2896 2011-10-29 01:31
浏览 43

PHP中的循环和数组[关闭]

I have some php that hits a website. scrapes it for an item and then a price. i am having trouble joining them so i get

item 1 price 1
item 2 price 2

what i am getting is

item 1 price 1
item 1 price 2
item 1 price 3
item 2 price 1
item 2 price 2
item 2 price 3

here is my code

foreach($matches[0] as $item){
    foreach ($matchprice[0] as $pricevalue)    {    
        echo '<span style="font-weight:normal; font-size: 12pt;';
        echo $item;
        echo $pricevalue;
        echo "<br />";
    }
}

I have tried moving the items in and around the loops and using counts and even tried merging the arrays. All i got was array array as an out put. I hope i have made this clear enough.

Thanks for any help.

  • 写回答

4条回答 默认 最新

  • dss087358 2011-10-29 01:36
    关注

    use a simple for loop, like so:

    for($i = 0; $i < count($matches[0]); $i++) {
      echo '<span>', $matches[0][$i], ", ", $matchprice[0][$i], '</span/>;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度