【发布时间】:2018-08-24 12:33:42
【问题描述】:
在我的in_array 中,我可以从$row->guestEmail 中排除特定术语吗?
例如,@example.com 和 example1.com 是 $row->guestEmail 值的禁止子字符串。
这是我尝试过的:
foreach ($json->data as $row) {
if (!in_array($row->guestEmail, $emails)
&& date('Y-m-d', strtotime($row->endDate))== 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;
}
}
【问题讨论】:
-
你的意思是你不想在数组中包含example和example1.com?
-
$emails中有什么数据? -
它应该已经适用于您的实际代码
!in_array($row->guestEmail, $emails)。您是否将要排除的电子邮件放在$emails array中? -
您可以过滤以仅获取需要可迭代的数据。例如使用
array_filter之前使用foreach 到$json->data
标签: php object filtering blacklist