php - Count how many duplicate and unique values I have in my array -


i have array this:

array (size=6) 0 =>       array (size=1)       'test' => string 'aqhrmvbw7utgobjnzkqrp' (length=30)    1 =>  array (size=1)      'test' => string 'aqhrmu8hoojpnckufkgld' (length=30)    2 =>       array (size=1)       'test' => string 'aqhrmu7+bdwm7pmpzekew' (length=30)    3 =>       array (size=1)      'test' => string 'aqhrmu74stu6yp4gseee8' (length=30)    4 =>       array (size=1)      'test' => string 'aqhrmoqqaohugxj7t0et8' (length=30)    5 =>       array (size=1)      'test' => string 'aqhrmoqqaohugxj7t0et8' (length=30) 

now want count how many values there in array , how many uneven have.

as can see last 2 results same in array , other 4 unique. want final result be:

even: 2 uneven: 4 

$results = array(); foreach($array $key => $value) {      if(!isset($results[$value['test']])) $results[$value['test']]=0;      $results[$value['test']]++; }  //count , uneven $uneven = 0; $even = 0; foreach($results $key => $count) {     if($count>1) $even += $count;     else $uneven++; }  echo 'even: '.$even.'<br>'; echo 'uneven: '.$uneven.'<br>'; 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -