如何将PHP变量从一个函数传递到另一个函数?

问题描述 投票:-3回答:1

我试图从一个静态函数到另一个静态函数的PHP变量,因为使用$ _GET接收PHP变量的值。我正在获取客户ID,我想在另一个功能中使用客户ID。

$ _GET的第一个函数:

static function createProject($pParamArray)
{

    $result = $pParamArray;

    $result['result'] = '';
    $result['useraccount'] = array();
    $result['updategroupcode'] = 0;
    $result['updateaccountdetails'] = 0;
    $result['updateaccountbalance'] = 0;
    $result['updategiftcardbalance'] = 0;
    $result['ssotoken'] = '';
    $result['ssoprivatedata'] = array();
    $result['assetservicedata'] = array();
    $result['ssoexpiredate'] = '';
    $result['projectname']="Personalised Parties - ".date('D M Y');
    $result['guestworkflowmode'] = 1;
    $result['cansignin'] = 0;
    $result['editprojectnameonfirstsave'] = 0;

    //grabs customer id from Magento 2
    $result['userdata'] = $_GET['customerid'];


    return $result;


}

第二个函数我试图从另一个函数调用PHP变量:

static function initialise($pParamArray)
{   

    //create customer 
    $customerData = [
        'customer_id' => $result['userdata'] //the PHP variable I'm trying to call from the other function
    ];
}

我怎么能这样做。我对PHP比较陌生。

php function variables
1个回答
3
投票

你可以这样做:

static function initialise($pParamArray)
{
    // call your first function and assign returned value to `$result`
    $result = self::createProject($pParamArray);

    //create customer 
    $customerData = [
        'customer_id' => $result['userdata']
    ];
}
© www.soinside.com 2019 - 2024. All rights reserved.