0

print array

array(
    'Order' => array(
        'id' => '1',
        'base_price' => '65',
        'min_price' => '95',            
    )
)

Is it possible to remove the key('Order') when you retrieving data? if Not how can I use array_shift or end in one line and to prevent below error?

I am getting this error Only variables should be passed by reference when I remove the key from array.

$orders = array_shift or end ($this->Order->read(null, $id));
debug($orders);

2 Answers 2

2

You want only id from it then following code will help you

 $arrOrderId=Set::extract("/Order/id",$data);

here $data is your array from where you want to delete this "Order" key.

You will get following array when you do debug($arrOrderId);

[0]=>1

if you want base_price then write following code

$arrOrderId=Set::extract("/Order/base_price",$data);
Sign up to request clarification or add additional context in comments.

Comments

2

You can use Set functions for manipulating arrays:

Set::extract($array, 'Order');

Will output:

array(
    'id' => '1',
    'base_price' => '65',
    'min_price' => '95',            
)

If you need to do this on every output, you can override afterFind() method on your model.

Please see the docs:

http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::extract

http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::classicExtract

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.