How to get data in an array with PHP?
findParent() function returns the following array.
Array
(
[0] => Array
(
[order_item_id] => 3
[order_id] => 2
[product_id] => 77
[quantity] => 1
[price] =>开发者_StackOverflow中文版 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?
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'.
$order_id = $childlessorder[0]['order_id'];
$childlessorder = findParent($order_id);
$order_id = $childlessorder[0]['order_id'];
?
精彩评论