gpt4 book ai didi

php - 我的循环显示结果值时遇到问题

转载 作者:行者123 更新时间:2023-11-30 01:12:04 24 4
gpt4 key购买 nike

 $array_of_time = array ();
$start_time = strtotime ("$app_date 07:00");
$end_time = strtotime ("$app_date 22:00");
$mins = 04 * 60;

while ($start_time <= $end_time)
{
$array_of_time[] = date ('h:i a', $start_time);
$start_time += $mins;
}

echo "<div style='width:700px' class='time_slot_div'>";
echo "<p class='time_slot_p'> Time Slot :</p>";

foreach($array_of_time as $key=>$value)
{

for($i = 0; $i < count($app_data); $i++)
{
$book_time=$app_data[$i]["appointment_time"];
if($value==$book_time)
{
echo "<a class='time_slot_a_book'>$value</a>&nbsp;";
} else {
echo "<a href='#' onclick='get_time_value(\"$value\");' class='time_slot_a'>$value</a>&nbsp;";
}
}
}

echo "</div>";

这里 foreach 循环可以像 for 循环一样运行任意多次,但我想显示与 foreach 值和 for 循环值不匹配的链接。

像 7:20 am 这样的 foreach 循环值不是来自数据库,但是像 7:20 am 这样的 for 循环值来自数据库,所以如果 7:20 am==7:20 am 那么它运行的 if 语句工作正常,但问题是,如果我在 for 循环中得到 2 个值,它就会运行 2 次。它应该只运行我的 div 一次。

最佳答案

如果浏览了您的网站,我会修改副本:

$array_of_time = array ();
$start_time = strtotime ("$app_date 07:00");
$end_time = strtotime ("$app_date 22:00");
$mins = 04 * 60;

while ($start_time <= $end_time)
{
$array_of_time[] = date ('h:i a', $start_time);
$start_time += $mins;
}

echo "<div style='width:700px' class='time_slot_div'>";
echo "<p class='time_slot_p'> Time Slot :</p>";

foreach($array_of_time as $key=>$value)
{
//
// get the appointing state:
//
$bAppointed = false;
for($i = 0; $i < count($app_data); $i++)
{
$book_time = $app_data[$i]["appointment_time"];
$bAppointed = $value == $book_time;
if($bAppointed)
{
break;
}
}
//
// print the time slot:
//
if($bAppointed)
{
echo "<a class='time_slot_a_book'>$value</a>&nbsp;";
} else {
echo "<a href='#' onclick='get_time_value(\"$value\");' class='time_slot_a'>$value</a>&nbsp;";
}
}

echo "</div>";

这样更好吗?

关于php - 我的循环显示结果值时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19386510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com