Notice: Undefined offset: 0 in

后端 未结 14 1672
太阳男子
太阳男子 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:35

    function getEffectiveVotes($id) 
    

    According to the function header, there is only one parameter variable ($id). Thus, on line 27, the votes[] array is undefined and out of scope. You need to add another parameter value to the function header so that function getEffectiveVotes() knows to expect two parameters. I'm rusty, but something like this would work.

    function getEffectiveVotes($id, $votes)
    

    I'm not saying this is how it should be done, but you might want to research how PHP passes its arrays and decide if you need to explicitly state to pass it by reference

    function getEffectiveVotes($id &$votes)    <---I forget, no time to look it up right now.
    

    Lastly, call function getEffectiveVotes() with both arguments wherever it is supposed to be called.

    Cheers.

提交回复
热议问题