Notice: Undefined offset: 0 in

后端 未结 14 1663
太阳男子
太阳男子 2020-11-28 11:05

I am getting this PHP error, what does it mean?

Notice: Undefined offset: 0 in 
C:\\xampp\\htdocs\\mywebsite\\reddit_vote_tut\\src\\votes.php on line 41
         


        
14条回答
  •  青春惊慌失措
    2020-11-28 11:34

    You are asking for the value at key 0 of $votes. It is an array that does not contain that key.

    The array $votes is not set, so when PHP is trying to access the key 0 of the array, it encounters an undefined offset for [0] and [1] and throws the error.

    If you have an array:

    $votes = array('1','2','3');
    

    We can now access:

    $votes[0];
    $votes[1];
    $votes[2];
    

    If we try and access:

    $votes[3];
    

    We will get the error "Notice: Undefined offset: 3"

提交回复
热议问题