gpt4 book ai didi

php - 检查数组是否不为空

转载 作者:行者123 更新时间:2023-12-02 03:54:22 26 4
gpt4 key购买 nike

********更新************

var_dump: 字符串(0) ""

我试图检查数组的一部分是否不为空,然后显示代码,但代码无论如何都会显示。

我已经尝试过!is_null !empty。我不太确定哪个应该是正确的或者我应该选择:if (sizeof($book['Booking']['comments'])>0)

代码:

<?php if (!empty($book['Booking']['comments'])) {?>
<table width="100%" border="0">
<tbody>
<tr>
<td style="font-family:'Lucida Grande', sans-serif;font-size:12px;font-weight:normal;color:#666666;">
<?=$book['Booking']['comments']?>
</td>
</tr>
</tbody>
</table>
<? } ?>

数组:

Array
(
[Booking] => Array
(
[id] => 109
[user_id] => 1
[corporate_account_id] => 0
[id_ref] => RES000109
[price] => 178.00
[arrival] => 2011-10-18 00:00:00
[departure] => 2011-10-19 00:00:00
[rate_title] =>
[adult_guests] => 4
[child_guests] => 0
[company] => gravitate
[titlename] =>
[firstname] => John
[surname] => Doe
[address1] => 123 Fake St
[address2] =>
[city] => New York
[state] => NY
[postcode] => 12345
[country] => US
[phone] => 1111111111
[mobile] =>
[fax] =>
[email] => example@example.com
[comments] =>
[created] => 2011-10-18 13:40:47
[updated] => 2011-10-18 13:40:47
[status] => 1
[cancelled] => 0
[request_src] => website
[request_token] => 0
[token] => ayzrGnx
[survey_sent] => 0000-00-00 00:00:00
[survey_returned] => 0000-00-00 00:00:00
[send_sms] => 0
[payment_time] => 0000-00-00 00:00:00
[fullname] => John Doe
)

最佳答案

我怀疑它可能包含 (bool) FALSE,而 is_null() 则不然。

简单地尝试一下:

if ($book['Booking']['comments']) {

这也适用于任何计算结果为 FALSE 的内容,例如空字符串。

关于php - 检查数组是否不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7807630/

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