“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

后端 未结 28 1310
盖世英雄少女心
盖世英雄少女心 2021-01-24 14:18

I\'m running a PHP script and continue to receive errors like:

Notice: Undefined variable: my_variable_name in C:\\wamp\\www\\mypath\\index.php on line 10

28条回答
  •  感动是毒
    2021-01-24 14:42

    Those notices are because you don't have the used variable defined and my_index key was not present into $my_array variable.

    Those notices were triggered every time, because your code is not correct, but probably you didn't have the reporting of notices on.

    Solve the bugs:

    $my_variable_name = "Variable name"; // defining variable
    echo "My variable value is: " . $my_variable_name;
    
    if(isset($my_array["my_index"])){
        echo "My index value is: " . $my_array["my_index"]; // check if my_index is set 
    }
    

    Another way to get this out:

    ini_set("error_reporting", false)
    

提交回复
热议问题