PHP: variable not working inside of function?

后端 未结 5 901
滥情空心
滥情空心 2020-11-27 23:03
echo $path; //working
function createList($retval) {
    echo $path; //not working
    print \"
5条回答
  •  余生分开走
    2020-11-27 23:15

    As an alternative to using a global variable, just pass $path in. Of course, if you don't need the variable inside the function, don't bother!

    echo $path;
    function createList($retval, $path) {
        echo $path;
        print "";
        foreach ($retval as $value) {
                print "$value
    "; } print ""; print ""; }

提交回复
热议问题