Zusätzliche Daten, die zeigen:PHP: foreach (zusätzliche Daten angezeigt)
http://image.prntscr.com/image/41c1fbbdc1354ed2801f5afcfc5b4e0d.png
ich eine seltsame Art von Daten von foreach-Schleife habe. Meine Tage und Stunden werden zweimal wiederholt. (Bitte sehen Sie das Bild im Anhang). Aber ich möchte die Daten nicht in der letzten Zeile anzeigen. Kann jemand bitte mit Lösungen helfen. Dank
Mein Code ist hier: -
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Timings </button>
<div class="collapse" id="collapseExample">
<div class="well">
<?php
date_default_timezone_set('Australia/Melbourne');
$datetime = new \DateTime();
$listItem = array('<li class="active">', '</li>');
$curDay = date('l');
$status = array("Now Open" ,"Closed", "Opening Soon", "Closing Soon", "Open 24 hours", " ");
$times = $times = array(
1 => array('day' => 'Monday', 'open' => date($row_DetailRS1['monO']), 'close' => date($row_DetailRS1['monC'])),
2 => array('day' => 'Tuesday', 'open' => date($row_DetailRS1['tueO']), 'close' => date($row_DetailRS1['tueC'])),
3 => array('day' => 'Wednesday', 'open' => date($row_DetailRS1['wedO']), 'close' => date($row_DetailRS1['wedC'])),
4 => array('day' => 'Thursday', 'open' => date($row_DetailRS1['thurO']), 'close' => date($row_DetailRS1['thurC'])),
5 => array('day' => 'Friday', 'open' => date($row_DetailRS1['friO']), 'close' => date($row_DetailRS1['friC'])),
6 => array('day' => 'Saturday', 'open' => date($row_DetailRS1['satO']), 'close' => date($row_DetailRS1['satC'])),
7 => array('day' => 'Sunday', 'open' => date($row_DetailRS1['sunO']), 'close' => date($row_DetailRS1['sunC'])));
$html .= " <a href=''>"; echo $curDay; $html .="</a>
<table class='table table-striped' border='0' align='center' cellpadding='10' cellspacing='20'>
<tr>
<td>Days</td>
<td><span class='white-text' style='margin-right: 3em;'></td>
<td>Business Hours</td>
<td><span class='white-text' style='margin-right: 3em;'></td>
<td>Hours</td>
</tr>";
$i = 1;
$cd = $datetime->format('N');
$timenow = date("H:i:s", time());
// Create an array of day numbers that start with current day and loops around
$day_order = array_merge(range($cd, 7), range(1, $cd-1));
foreach ($day_order as $daynum): {
$oc = $times[$daynum];
$openingTime = $oc['open'];
$closingTime = $oc['close'];
$openingSoon = date('H:i:sA', strtotime($openingTime)-3600);
$closingSoon = date('H:i:sA', strtotime($closingTime)-3600);
if ($cd == $daynum) {
if ($openingTime == ' ' && $closingTime == ' ') {
$s = $status[4];
}
elseif ($timenow < $openingSoon || $timenow > $closingTime) {
$s = $status[1];
}
elseif ($timenow > $openingSoon && $timenow < $openingTime) {
$s = $status[2];
}
elseif ($timenow > $closingSoon && $timenow < $closingTime) {
$s = $status[3];
} else {
$s = $status[0];
}
} else {
$s = " ";
}
$html .= "<tr>";
$html .= "<td>". $oc['day']."</td>";
$html .= "<td> <span class='white-text' style='margin-right: 3em;'> </td>";
$html .= "<td>".$openingTime." to ".$closingTime."</td>";
$html .= "<td> <span class='white-text' style='margin-right: 3em;'> </td>";
$html .= "<td>".$s."</td>";
$html .= "</tr>";
}
$datetime->add(new \DateInterval('P1D'));
endforeach;
$html .= "</table>";
echo $html;
?>
Wo ist das Bild? –
Welche letzte Zeile meinst du? Können Sie angeben? Bitte kürzen Sie Ihren Code auf nur notwendige Elemente. – rbr94
der Link ist hier http://i.stack.imgur.com/xAAZj.png Ich kann noch kein Bild einbetten :( –