tqla Posted February 1, 2010 Share Posted February 1, 2010 I have an array called $list that has many rows. There is a number in the "amount" column. How can I look through the array and count the ones that have a number higher than 0 and then echo the total. In short: Look at the array $list Count the rows that don't have 0 in the "amount" column. $newList = sizeof($rows-with-no-0-in-amount-column) Thanks! Link to comment https://forums.phpfreaks.com/topic/190584-help-with-an-array/ Share on other sites More sharing options...
taquitosensei Posted February 1, 2010 Share Posted February 1, 2010 $count=0; foreach($list as $array) { $count=($array['amount'] > 0)?$count++:$count; } Link to comment https://forums.phpfreaks.com/topic/190584-help-with-an-array/#findComment-1005172 Share on other sites More sharing options...
tqla Posted February 3, 2010 Author Share Posted February 3, 2010 Thanks Taquitosensei, but how do I echo the result. I've tried echo $count; but get a result of 0. Which can't be right because their are many 1,2 and 3 entries. Link to comment https://forums.phpfreaks.com/topic/190584-help-with-an-array/#findComment-1005872 Share on other sites More sharing options...
teamatomic Posted February 3, 2010 Share Posted February 3, 2010 Do a print_r and let us see what the array looks like. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/190584-help-with-an-array/#findComment-1005879 Share on other sites More sharing options...
tqla Posted February 3, 2010 Author Share Posted February 3, 2010 Hey Teamatomic, I can't show the results of print_r here because it's real information (and 100s of rows) but doing so I did discover that it's a multidimensional array. I've also tried $result= array_count_values ($input_array) with a while loop and got no result. Hmmm. I guess multidimensional arrays are hard to count. Link to comment https://forums.phpfreaks.com/topic/190584-help-with-an-array/#findComment-1006273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.