Home >Backend Development >PHP Tutorial >$out = ""然后再$out .= 与直接 $out=啥的 有什么区别 上面有例子

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

WBOY
WBOYOriginal
2016-06-13 10:32:281371browse

$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文件最后一行内容
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn