输出出现未定义变量提示:Notice: Undefined variable: str in

WBOY
Release: 2016-06-23 14:22:18
Original
1532 people have browsed it

function Call(){
    for($i=0;$i       {
       $str.= $i."
";
       }
    return $str;
}

echo Call();

输出进出现Notice: Undefined variable提示


回复讨论(解决方案)

Notice: Undefined variable
是说你使用了未经赋值的变量的值

在你的 $str.= $i."
"; 中首次进入时 $str 没有被赋过值,所以要报错

function Call(){    $str = ''; //这句不能少    for($i=0;$i<=10;$i++)      {       $str.= $i."<br>";       }    return $str;}echo Call();
Copy after login

就是提示你的变量没有没有被定义过。

或者将notice级别错误屏蔽掉

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template