theITvideos Posted November 9, 2010 Share Posted November 9, 2010 Hi there I am working on PHP form which has an array named: $productOptions. When I do: print_r($productOptions); it returns: Array ( [124] => Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) [114] => Array ( [optionId] => 114 [optionName] => acer fast [optionListId] => 28 [dateCreated] => 2010-11-01 02:04:53 [enabled] => 1 [optionQtyId] => 83 [productId] => 40 [quantity] => 0 ) Now from this Array, I would like to check if the quantity if greater than Zero. so I tried: if (productOptions[quantity] > 0){ echo "blah blah..." } But for getting the quantity, the part: productOptions[quantity] returns nothing. Am I doing this correctly? Please reply. Thank you Link to comment https://forums.phpfreaks.com/topic/218217-reading-this-array-in-php/ Share on other sites More sharing options...
MadTechie Posted November 9, 2010 Share Posted November 9, 2010 Close but no this is your array Array ( [124] => Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) [114] => Array ( [optionId] => 114 [optionName] => acer fast [optionListId] => 28 [dateCreated] => 2010-11-01 02:04:53 [enabled] => 1 [optionQtyId] => 83 [productId] => 40 [quantity] => 0 ) So you see quantity is in an array in 124 and 114 So your need to do this if ($productOptions['124']['quantity'] > 0){ echo "blah blah..." } so $X = $productOptions['124'] would return an array Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) then $X['quantity'] would return 7 So in a loop foreach($productOptions as $X){ if ($X['quantity'] > 0){ echo "ID ".$X['optionId']." has ".$X['quantity']; } } Hope this helps Link to comment https://forums.phpfreaks.com/topic/218217-reading-this-array-in-php/#findComment-1132321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.