Jump to content

Coding help with 'Count'


RON_ron

Recommended Posts

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));

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.