kts Posted August 6, 2009 Share Posted August 6, 2009 Hey everyone, I have this array that I'm trying to grab the "value" piece from, but I'm extremely confused... when I print_r($order->products); Array ( [0] => Array ( [qty] => 1 [name] => book test 39 [model] => [tax] => 0.0000 [price] => 1.0000 [final_price] => 1.0000 [products_warehouse_location] => [attributes] => Array ( [0] => Array ( [option] => Size [value] => Youth Large [prefix] => + [price] => 0.0000 ) ) ) ) echoing $order->products[$i]['name']; shows the name, but echoing $order->products[$i]['value'] shows nothing... Am I missing something, is it a different array? Quote Link to comment https://forums.phpfreaks.com/topic/169123-multidimensional-array-problem/ Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 use this when echoing arrays/objects: echo nl2br(str_replace(' ',' ',print_r($order->products))); $order->products[0]['attributes'][0]['value'] you've got an array of products but each product has information attached to it ALSO in an array so you have an array of an array of product data each product data can have different attributes such as size etc etc etc and each group of attributes are in an array so in the end you have array of an array of product data where the different attributes of the product are an array Quote Link to comment https://forums.phpfreaks.com/topic/169123-multidimensional-array-problem/#findComment-892326 Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 I believe you to have single quotes around your keys when you have an associative array Quote Link to comment https://forums.phpfreaks.com/topic/169123-multidimensional-array-problem/#findComment-892327 Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 I believe you to have single quotes around your keys when you have an associative array yeah, but it doesn't matter for numeric the problem was - $order->products[$i]['value'] doesn't exist Quote Link to comment https://forums.phpfreaks.com/topic/169123-multidimensional-array-problem/#findComment-892328 Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 ahh ok I misread something in there haha. Quote Link to comment https://forums.phpfreaks.com/topic/169123-multidimensional-array-problem/#findComment-892339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.