phpworker Posted July 9, 2010 Share Posted July 9, 2010 Hi In the following code,at the 21st line, the code to print the value of the variable $cartContent is: print_r ($cartContent); function getCartContent() { $cartContent = array(); $sid = session_id(); $sql = "SELECT ct_id, ct.pd_id, ct_qty, pd_name, pd_price, pd_thumbnail, pd.cat_id FROM tbl_cart ct, tbl_product pd, tbl_category cat WHERE ct_session_id = '$sid' AND ct.pd_id = pd.pd_id AND cat.cat_id = pd.cat_id"; $result = dbQuery($sql); while ($row = dbFetchAssoc($result)) { if ($row['pd_thumbnail']) { $row['pd_thumbnail'] = WEB_ROOT . 'images/product/' . $row['pd_thumbnail']; } else { $row['pd_thumbnail'] = WEB_ROOT . 'images/no-image-small.png'; } $cartContent[] = $row; } print_r ($cartContent); return $cartContent; } I get the output at runtime as, Array ( [0] => Array ( [ct_id] => 120 [pd_id] => 22 [ct_qty] => 4 [pd_name] => volvo1 [pd_price] => 100.00 [pd_thumbnail] => /plaincart/images/no-image-small.png [cat_id] => 14 ) ) When i want to see only the ct_id key and its value which is 120,ignoring all other keys and values. what is the code for it.. thanks phpworker Link to comment https://forums.phpfreaks.com/topic/207263-output-of-the-array-variable/ Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2010 Share Posted July 9, 2010 echo $cartContent['ct_id']; Link to comment https://forums.phpfreaks.com/topic/207263-output-of-the-array-variable/#findComment-1083666 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2010 Share Posted July 9, 2010 If you only want to see one entry in the array, only echo one entry: <?php echo $cartContent['ct_id']; ?> Ken Link to comment https://forums.phpfreaks.com/topic/207263-output-of-the-array-variable/#findComment-1083667 Share on other sites More sharing options...
phpworker Posted July 9, 2010 Author Share Posted July 9, 2010 Hi can we use print_r ($cartContent[0]['ct_id']); and what are all other codes to display it.. thanks karthika Link to comment https://forums.phpfreaks.com/topic/207263-output-of-the-array-variable/#findComment-1083683 Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2010 Share Posted July 9, 2010 Oh, I didn't notice it was a multidimensional array. But no, if you just want the value, you don't use print_r(), you use echo. Try it both ways and you'll see why. echo $cartContent[0]['ct_id']; Link to comment https://forums.phpfreaks.com/topic/207263-output-of-the-array-variable/#findComment-1083689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.