嗨,有人能向我解释一下,如果我以前有一个"if"语句,为什么我会得到一个意外的else吗?
PHP
<?php if($post_image=="") echo "There is no image" else echo '<img src="../img/'.$post_image.'">' ?>
您需要用分号终止语句:
<?php if($post_image=="") echo "There is no image"; else echo '<img src="../img/'.$post_image.'">'; ?>
您缺少分号。您有:
<?php if($post_image=="") echo "There is no image" else echo '<img src="../img/'.$post_image.'">' ?>
^---- here and here ---^
您的需求:
<?php if($post_image=="") echo "There is no image"; else echo '<img src="../img/'.$post_image.'">'; ?>