我最近在我的代码中遇到了一个奇怪的问题。我需要检查 if 语句中的变量值,但它总是失败,值是(假),在回显值后一切正常。
示例(我不记得确切的代码):
for ($i=0; $i<=$limit; $i++) {
if ($object->data[$i]['name']) {
echo 'name: '.$object->data[$i]['name'];
}
}
上面的脚本总是返回 false(不显示用户名)
但是下面的脚本有效(即使我评论了 echo 语句)
for ($i=0; $i<=$limit; $i++) {
// echo $object->data[$i]['name'];
if ($object->data[$i]['name']) {
echo 'name: '.$object->data[$i]['name'];
}
}
这发生在任何人身上吗?是否有一个原因?
好的...这是原始代码:
<?php if ( $data->apartments[$i]['price']['price1']->value ) { ?>
<div class="prices">
<table border="0" width="100%" cellpadding="0" style="border-collapse: collapse">
<tr>
<td colspan="2" style="border-bottom: 1px dashed #E36300">
<h3>PRICE LIST</h3>
</td>
</tr>
<tr><td> </td><td> </td></tr>
<?php
//$data->apartments[$i]['price']['price_date1']->value;
//$data->apartments[$i]['price']['price_date2']->value;
//$data->apartments[$i]['price']['price_date3']->value;
//$data->apartments[$i]['price']['price_date4']->value;
//$data->apartments[$i]['price']['price_date5']->value;
//$data->apartments[$i]['price']['price_date6']->value;
//$data->apartments[$i]['price']['price_date7']->value;
//$data->apartments[$i]['price']['price_date8']->value;
//$data->apartments[$i]['price']['price_date9']->value;
//$data->apartments[$i]['price']['price1']->value;
//$data->apartments[$i]['price']['price2']->value;
//$data->apartments[$i]['price']['price3']->value;
//$data->apartments[$i]['price']['price4']->value;
//$data->apartments[$i]['price']['price5']->value;
//$data->apartments[$i]['price']['price6']->value;
//$data->apartments[$i]['price']['price7']->value;
//$data->apartments[$i]['price']['price8']->value;
//$data->apartments[$i]['price']['price9']->value;
for ( $pc=0; $pc<=10; $pc++ ) {
if ( $data->apartments[$i]['price']['price_date'.$pc]->value ) {
echo "<tr>";
echo "<td style='border: 1px solid #E36300' align='left' valign='top' width='50%'>".$data->apartments[$i]['price']['price_date'.$pc]->value."</td>";
echo "<td style='border: 1px solid #E36300' align='right' valign='top' width='50%'>".$data->apartments[$i]['price']['price'.$pc]->value." ".$data->apartments[$i]['price']['price_currency']->value."</td>";
echo "</tr>";
}
}
?>
</table>
</div>
<?php } ?>