2014-04-07 106 views
1

我正在循環訪問某些數據併爲每一行打印。除了在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>"); 
    } 
} 
+1

等等,我很困惑;又是什麼問題? :) – summea

+0

問題已回答。等待10分鐘。 –

回答

3
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>"); 
    } 
} 

希望這個作品。

+0

完美,應該已經知道了。 –

+1

或'$ i <($ rsc - 1)':)使用關係表達式而不是檢查(in)的等式是一個好主意。好的答案,但。 +1 – cepradeep

相關問題