Giving my function access to outside variable

前端 未结 6 1667
梦毁少年i
梦毁少年i 2020-11-22 14:32

I have an array outside:

$myArr = array();

I would like to give my function access to the array outside it so it can add values to it

6条回答
  •  长发绾君心
    2020-11-22 15:16

    $myArr = array();
    
    function someFuntion(array $myArr) {
        $myVal = //some processing here to determine value of $myVal
        $myArr[] = $myVal;
    
        return $myArr;
    }
    
    $myArr = someFunction($myArr);
    

提交回复
热议问题