-2

I am trying to take a PHP variable from one static function to another as the value of the PHP variable is received using a $_GET. I am getting the customers ID and I want to use the customer ID in another function.

First Function with the $_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;


}

Second Function where I'm trying to call the PHP variable from the other function:

static function initialise($pParamArray)
{   

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

How would I be able to do this. I'm relatively new to PHP.

3
  • 2
    Am I missing something or is the answer actually as simple as calling the function? Commented Feb 20, 2018 at 16:59
  • $customerData = self::createProject($pParamArray); Commented Feb 20, 2018 at 16:59
  • Possible duplicate of How to pass a PHP variable from one function to another? Commented Feb 20, 2018 at 17:08

1 Answer 1

3

You can do it like this:

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']
    ];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.