0

findParent() function returns the following array.

Array
(
    [0] => Array
        (
            [order_item_id] => 3
            [order_id] => 2
            [product_id] => 77
            [quantity] => 1
            [price] => 268.00
        )

)

I want to get 2 in [order_id].

I tried the following but it does not work.

$childlessorder = findParent($order_id);
$order_id = $childlessorder['order_id'];

Can anyone tell me how to get data in an array?

1

3 Answers 3

4

Try using:

$childlessorder = findParent($order_id);
$order_id = $childlessorder[0]['order_id'];

The function findParent() is returning a two dimensional array as is apparent from the two Array words in the dump. So to access any value from this array we need to use two indices. Think of this as a matrix with the element you're interested lying in xth row yth column. With x being 0 and y begin 'order_id'.

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

Comments

0
$order_id = $childlessorder[0]['order_id'];

Comments

0
$childlessorder = findParent($order_id);
$order_id = $childlessorder[0]['order_id'];

?

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.