我通常设置我所有的变量,即使它们可能不会返回任何东西。但现在我想知道:
如果我回显一个空变量会有什么危害?
例如。
<?php
$a = 'a';
$b = 'b';
if($a==$b)
{
$data = 'Yes they where the same';
};
echo $data;
?>
为什么我必须这样做?
<?php
$data = ''; // declare varibale
$a = 'a';
$b = 'b';
if($a==$b)
{
$data = 'Yes they where the same';
};
echo $data;
?>
感谢您的回答!
扩展问题:
什么是最佳实践:
$data = '';
或者
$data;
或使用
if (isset($data)){
echo $data;
}