我正在尝试将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比较陌生。
答案 0 :(得分: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']
];
}