jord49 jord49 - 1 year ago 77
PHP Question

Change foreach loop to a for loop

I'm quite new to PHP. How can I change this foreach loop to only loop twice?


foreach($results as $row):


Answer Source

Try this code, you just need a counter variable, initialize your counter variable from zero and increment it after each iteration.

    $counter = 0; 
    foreach($results as $row) {
         //your code
         if($counter == 1)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download