Reaching inside arrays within an arrays

时间:2015-10-17 21:16:30

标签: php arrays

Hey guys i have an issue which i can't seem to find an answer to.

So when i started accessing the array that i need.i did a print_r(products['options']) i got arrays that are from 0 to 3

so i got inside the array that i needed which is number 2 print_r(products['options'][2])

this printed out the options that i needed which are

Array ( [product_option_id] => 263 [option_id] => 16 [name] => Place [type] => checkbox [option_value] => Array ( [0] => Array ( [product_option_value_id] => 99 [option_value_id] => 109 [name] => Iceland [image] => [quantity] => 0 [subtract] => 0 [price] => 0.0000 [price_prefix] => + [weight] => 0.00000000 [weight_prefix] => + ) ) [required] => 0 )

How do i acces the 2-nd array here? which is this:

[0] => Array ( [product_option_value_id] => 99 [option_value_id] => 109 [name] => Iceland [image] => [quantity] => 0 [subtract] => 0 [price] => 0.0000 [price_prefix] => + [weight] => 0.00000000 [weight_prefix] => + ) ) [required] => 0 )

If i try to acces it like this: print_r(products['options'][2][0])

I get an error Notice: Undefined offset: 0. Which i assume it just cant find the array 0.

The end goal here is to dig down and get [name] => Iceland

if i access it like this print_r(products['options'][2][0]['name']) i get the first variable inside the array that is [name] => Place

1 个答案:

答案 0 :(得分:1)

print_r(products['options'][2]['option_value'][0]['name'])