每次刷新页面时我想尝试做的事情$insertedBookings
应该添加输入的数量,以便它变为总数但是它仍然保持在6
总共11
1}}要输入的项目。
代码已更新:
$insertedBookings = 0;
foreach($json->data as $row)
{
if (!in_array($row->guestEmail, $emails) && date('Y-m-d', strtotime($row->startDate)) == date('Y-m-d'))
{
$insertedBookings ++;
$guests[] = array(
'FirstName' => $row->guestFirstName,
'LastName' => $row->guestLastName,
'email' => $row->guestEmail,
'country' => $row->guestCountry,
'check-in_date' => $row->startDate,
'check-out_date' => $row->endDate,
);
$emails[] = $row->guestEmail;
}
}
// Insert to IF HERE
if (!isset($_SESSION["totalInsertedBookings"]))
{
$_SESSION["totalInsertedBookings"] = $insertedBookings;
}
$currentInsertedBooking = $_SESSION["totalInsertedBookings"];
**Code:**
$insertedBookings = 0;
foreach($json->data as $row)
{
if (!in_array($row->guestEmail, $emails) && date('Y-m-d', strtotime($row->startDate)) == date('Y-m-d'))
{
$guests[] = array(
'FirstName' => $row->guestFirstName,
'LastName' => $row->guestLastName,
'email' => $row->guestEmail,
'country' => $row->guestCountry,
'check-in_date' => $row->startDate,
'check-out_date' => $row->endDate,
);
$emails[] = $row->guestEmail;
$insertedBookings = count($guests);
}
}
// Insert to IF HERE
if (!isset($_SESSION["totalInsertedBookings"]))
{
$_SESSION["totalInsertedBookings"] = $insertedBookings;
}
$currentInsertedBooking = $_SESSION["totalInsertedBookings"];
答案 0 :(得分:0)
因为count($ guests)正在计算$ guests数组中6的元素数(FirstName,LastName等)。