0

i have a problem with send variable data from function to another function in a same controller orderProcess :

this my controller orderProcess :

function endOrder(){
    $datap['invoice_pad'] = $invoice;
    $datap['date_end'] = date('d-m-Y');
    $datap['total_order'] = $grt;
    //$datap i want send to the function controller order()
}

function order(){
    //here should be $datap accepted
}

3 Answers 3

1

function endOrder() {

$datap['invoice_pad'] = $invoice;

$datap['date_end'] = date('d-m-Y');

$datap['total_order'] = $grt;

$this->order($datap);

}

function order($data){

echo $data['invoice_pad'];

echo $data['date_end'];

echo $data['total_order'];

}

Sign up to request clarification or add additional context in comments.

Comments

0
function endOrder(){
    $datap['invoice_pad'] = $invoice;
    $datap['date_end'] = date('d-m-Y');
    $datap['total_order'] = $grt;
    return $datap;
}

function order(){
    $datap = $this->endOrder();
}

1 Comment

While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.
0

Usually I will declare a variable and use it to pass around any data that is needed. But above answer also able to achieve what you wanted.

function __construct()
{
    $this->_datap = [];
}

function endOrder()
{
    $this->_datap['invoice_pad'] = $invoice;
    $this->_datap['date_end']    = date('d-m-Y');
    $this->_datap['total_order'] = $grt;
}

function order(){
    print_r(this->_datap);
}

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.