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

后端 未结 28 937
盖世英雄少女心
盖世英雄少女心 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 15:01

    undefined index means in an array you requested for unavailable array index for example

    
    

    undefined variable means you have used completely not existing variable or which is not defined or initialized by that name for example

    
    

    undefined offset means in array you have asked for non existing key. And the solution for this is to check before use

    php> echo array_key_exists(1, $myarray);
    

提交回复
热议问题