【问题标题】:Check if Variable is 2 less than another Variable检查变量是否比另一个变量小 2
【发布时间】:2014-05-20 05:06:20
【问题描述】:

我正在遍历一些数据并打印每一行。我对每一行都做同样的事情,除了在满足 for 循环之前的最后一行我想省略我打印的东西之一。这是我正在使用的代码。

$i = 5;    

for($i=0; $i < $rsc; $i++) {


    print("<div><p>Date</p></div><div><p>My Name</p></div>");
    print("<div><p>Comment</p></div>");

    //This next piece should not print on the last run through.

    if(It's not the last one){
    print("<div><p> My Section Break</p></div>");
    }
}

【问题讨论】:

  • 等等,我很困惑;又是什么问题? :)
  • 问题已得到解答。等待 10 分钟。

标签: php html css loops for-loop


【解决方案1】:
for($i=0; $i < $rsc; $i++) {


    print("<div><p>Date</p></div><div><p>My Name</p></div>");
    print("<div><p>Comment</p></div>");

    //This next piece should not print on the last run through.

    if($i!=$rsc-1){
    print("<div><p> My Section Break</p></div>");
    }
}

希望这行得通。

【讨论】:

  • 完美,早该知道。
  • $i &lt; ($rsc - 1) :) 使用关系表达式而不是检查(不)相等性是个好主意。不过,很好的答案。 +1
猜你喜欢
  • 2017-06-23
  • 1970-01-01
  • 1970-01-01
  • 2020-01-16
  • 2021-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多