Why am I getting an “Undefined variable” notice in PHP?

后端 未结 2 974
借酒劲吻你
借酒劲吻你 2021-01-22 19:24

So I have the following:




Name:
相关标签:
2条回答
  • 2021-01-22 20:07

    You need to set the variable to be global for that to work.

    At the start of the show_form method, add this code:

    global $defaults;
    

    Or, a better solution as pointed out already is to return the variable and use $defaults = show_form().

    0 讨论(0)
  • 2021-01-22 20:21

    $defaults is a local variable within the scope of the show_form function. You'll want to return it from the function and change your first line of code to this:

    $defaults = show_form();
    
    0 讨论(0)
提交回复
热议问题