首页  >  文章  >  后端开发  >  $out = ""然后再$out .= 与直接 $out=啥的 有什么区别 上面有例子

$out = ""然后再$out .= 与直接 $out=啥的 有什么区别 上面有例子

WBOY
WBOY原创
2016-06-13 13:24:35908浏览

$out = ""然后再$out .= 与直接 $out=啥的 有什么区别 下面有例子

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
    fputs($fp, $domain . "\r\n");
    $out = "";
    while (!feof($fp)){$out .= fgets($fp);}
    fclose($fp);


问下 这里的 
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$out = "";
    while (!feof($fp)){$out .= fgets($fp);}

于与
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
    while (!feof($fp)){$out= fgets($fp);}


有没区别 区别在哪

------解决方案--------------------
初始化操作,如果不初始化的话 $out的类型是null,与你想要的string不同 ,你可以var_dump看一下

如果用$out来做条件判断的话,不初始化的话,可能会得到不可预料的结果
------解决方案--------------------
$out = "";
while (!feof($fp)){$out .= fgets($fp);}
可以取到$fp文件所有的内容

$out = "";
while (!feof($fp)){$out = fgets($fp);}
取到的是$fp文件最后一行内容
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn