简体   繁体   中英

convert the result set foreach to for loop in php

I am doing a project in codeigniter.Here I want to fetch the fields time and url to view.I want to show something like this 在此处输入图片说明

The first field is time and second one is url.I used the following code to fetch the value

foreach ($path as $row) {
    ?>
    <tr>
        <td>
            <a href="#">
                <div class="span6 pull-left"><?php echo $row->time;</div>
                <div class="span3 pull-left"><?php echo $row->url ?></div>
            </a>

        </td>
    </tr>
    <?php
}
?>

But actually the first row of time is the difference between the time on first row and the second row.And the time on second row is the difference between time on second row and third row so on.I have tried with foreach loop.But I didnt get any idea to implement this.Anyone help me for converting this foreach loop to for loop to accomplish the task.

Thanks in advance.

maybe something like..

for( $i = 0 ; $i < count($path) ; $i++ ) {
    $time = $path[$i]->time - $path[$i+1]->time;
}

be aware issue with last index..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM