Heim >Backend-Entwicklung >PHP-Tutorial >输出出现未定义变量揭示:Notice: Undefined variable: str in

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:47:221276Durchsuche

输出出现未定义变量提示:Notice: Undefined variable: str in
function Call(){
    for($i=0;$i      {
       $str.= $i."
";
       }
    return $str;
}

echo Call();

输出进出现Notice: Undefined variable提示
------解决方案--------------------
Notice: Undefined variable
是说你使用了未经赋值的变量的值

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

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn