Canman2005 Posted April 2, 2010 Share Posted April 2, 2010 Hi all I need to a count on my array, i'm wondering if this is the best way to do it foreach($_SESSION['basket'] as $key => $value) { $values = $values + $value; } print $values Thanks Link to comment https://forums.phpfreaks.com/topic/197348-php-array-count/ Share on other sites More sharing options...
ignace Posted April 2, 2010 Share Posted April 2, 2010 Nope. $basket_count = sizeof($_SESSION['basket']); Link to comment https://forums.phpfreaks.com/topic/197348-php-array-count/#findComment-1035846 Share on other sites More sharing options...
xX_SuperCrazy_Xx Posted April 2, 2010 Share Posted April 2, 2010 Hi there, If you just want to count the total number of elements in your array, then you can use the count function echo count($_SESSION['basket']); Regards Link to comment https://forums.phpfreaks.com/topic/197348-php-array-count/#findComment-1035850 Share on other sites More sharing options...
salathe Posted April 2, 2010 Share Posted April 2, 2010 I need to a count on my array, i'm wondering if this is the best way to do it Your code can be replaced with: $values = array_sum($_SESSION['basket']); print $values; Check out the array_sum documentation for usage notes and examples. Link to comment https://forums.phpfreaks.com/topic/197348-php-array-count/#findComment-1035856 Share on other sites More sharing options...
ignace Posted April 2, 2010 Share Posted April 2, 2010 Use salathe's method I misread your post Link to comment https://forums.phpfreaks.com/topic/197348-php-array-count/#findComment-1035868 Share on other sites More sharing options...
Canman2005 Posted April 2, 2010 Author Share Posted April 2, 2010 thanks guys Link to comment https://forums.phpfreaks.com/topic/197348-php-array-count/#findComment-1035903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.