RON_ron Posted November 30, 2010 Share Posted November 30, 2010 How to get the count if any of this ($ArrayDrRes) contain the word "APPROVED"? $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); $Array2 = array('APPROVED'); $count3 = count( array_intersect($Array1, $Array2) ); echo $count3; Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/ Share on other sites More sharing options...
trq Posted November 30, 2010 Share Posted November 30, 2010 Is that 'you want to get the total count if the value "APPROVED" appears within the array? Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141243 Share on other sites More sharing options...
RON_ron Posted November 30, 2010 Author Share Posted November 30, 2010 yes. Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141245 Share on other sites More sharing options...
trq Posted November 30, 2010 Share Posted November 30, 2010 $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); if (in_array('APPROVED', $Array1)) { echo count($Array1); } Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141247 Share on other sites More sharing options...
RON_ron Posted November 30, 2010 Author Share Posted November 30, 2010 Thanks thorpe! Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141249 Share on other sites More sharing options...
RON_ron Posted November 30, 2010 Author Share Posted November 30, 2010 always returns the number of fields. $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); if (in_array('APPROVED', $Array1)) { echo count($Array1); } This did not work either. $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); echo count(in_array('APPROVED', $Array1)); Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141265 Share on other sites More sharing options...
trq Posted November 30, 2010 Share Posted November 30, 2010 So.. explain what you want it to return. Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141272 Share on other sites More sharing options...
RON_ron Posted November 30, 2010 Author Share Posted November 30, 2010 It returns the TOTAL number of fields, I want only the number of fields which contain the word "APPROVED" E.g. The database only contain 2 fields with "APPROVED". Instead of 2 it always returns 8. Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141273 Share on other sites More sharing options...
trq Posted November 30, 2010 Share Posted November 30, 2010 It returns the TOTAL number of fields, I want only the number of fields which contain the word "APPROVED" E.g. Currently it always returns 8. Yeah, that's exactly what you asked here. Anyway, moving on. $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); $result = array_count_values($Array1); if (isset($result['APPROVED'])) { echo $result['APPROVED']; } There's always the manual too you know? http://au2.php.net/manual/en/ref.array.php It really is the best way to learn. Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141275 Share on other sites More sharing options...
RON_ron Posted November 30, 2010 Author Share Posted November 30, 2010 Thank you thorpe! Link to comment https://forums.phpfreaks.com/topic/220208-coding-help-with-count/#findComment-1141279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.