JT Nolan
JT Nolan

Reputation: 1210

Check if Variable is 2 less than another Variable

I am looping through some data and printing for every row. I do the same thing for every row except on the last one before the for loop is satisfied I want to omit one of the things I print. Here is the code I'm using.

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

Upvotes: 1

Views: 85

Answers (1)

smistry
smistry

Reputation: 1126

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

Hope this works.

Upvotes: 3

Related Questions