PHP显示数组值

时间:2017-08-22 13:59:58

标签: php arrays object

我是php的初学者。我跟随阵列。我试图将我的阵列打印为07:30:00至08:20:00,08:20:00至09:10:00,99:10:00至10:00:00,依此类推。提前致谢

  Array ( 
    [0] => stdClass Object ( [time_id] => 1 [time] => 07:30:00 ) 
    [1] => stdClass Object ( [time_id] => 2 [time] => 08:20:00 ) 
    [2] => stdClass Object ( [time_id] => 3 [time] => 09:10:00 ) 
    [3] => stdClass Object ( [time_id] => 4 [time] => 10:00:00 ) 
    [4] => stdClass Object ( [time_id] => 5 [time] => 10:50:00 ) 
    [5] => stdClass Object ( [time_id] => 6 [time] => 11:40:00 ) 
    [6] => stdClass Object ( [time_id] => 7 [time] => 12:30:00 ) 
    [7] => stdClass Object ( [time_id] => 8 [time] => 13:20:00 ) 
    [8] => stdClass Object ( [time_id] => 9 [time] => 14:05:00 ) 
    [9] => stdClass Object ( [time_id] => 10 [time] => 14:50:00 ) 
    [10] => stdClass Object ( [time_id] => 11 [time] => 01:00:00 ) 

)

我已使用此代码

    <?php foreach ($time as $t) {


                        echo "<tr >";
                        echo "<td >";
                        echo "<input type = 'time'  value= $t->time>";
                        echo "</td >";

                        echo "<td >";
                        echo "<input type = 'time' value=$t->time >";
                        echo "</td >";
}

1 个答案:

答案 0 :(得分:1)

如果您只想以指定的格式打印数组,请使用以下代码。

$count=count($time);
for($i=0;$i<$count-1;$i++){
    // to display the time in the specified format.
    echo $time[$i]->time.' to '.$time[$i+1]->time."\n";
    // OR you can add your html code to display the time.

}

输出:

07:30:00 to 08:20:00
08:20:00 to 09:10:00
09:10:00 to 10:00:00
..........