dongqian5639 2012-04-24 15:19
浏览 37

从PHP中的多维数组中回应选择性数据(行)

I have an array coming from a .csv file. These are coming from a real estate program. In the second column I have the words For Sale and in the third column the words For Rent that are indicated only on the rows that are concerned. Otherwise the cell is empty. I want to display a list rows only For Sale for example. Of course then if the user clicks on a link in one of the rows, the appropriate page will be displayed. I can't seem to target the text in the column, and I can't permit that the words For Sale be used throughout the entire array because they could appear in another column (description for example). I have tried this, but to no avail.

/* The array is $arrCSV */
foreach($arrCSV as $book) {
    if($book[1] === For Sale) {
      echo '<div>';
    }
    echo '<div>';
    echo $book[0]. '<br>';
    echo $book[1]. '<br>';
    echo $book[2]. '<br>';
    echo $book[3]. '<br>';
    echo $book[6]. '<br><br><br>';
    echo '</div>';
}

I also tried this:

foreach($arrCSV as $key => $book) {
    if($book['1'] == 'For Sale') {
      echo '<div>';
    }
    echo '<div>';
    echo $book[0]. '<br>';
    echo $book[1]. '<br>';
    echo $book[2]. '<br>';
    echo $book[3]. '<br>';
    echo $book[6]. '<br><br><br>';
    echo '</div>';
}
  • 写回答

2条回答 默认 最新

  • douzhimao8656 2012-04-24 15:25
    关注

    Do you mean:

    foreach($arrCSV as $key => $book) {
        if($book['1'] == 'For Sale') {
            echo '<div></div>';
        }else{
            echo '<div>';
            echo $book[0]. '<br>';
            echo $book[1]. '<br>';
            echo $book[2]. '<br>';
            echo $book[3]. '<br>';
            echo $book[6]. '<br><br><br>';
            echo '</div>';
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口