I think I'm close with my code but I am trying to get the count() from the array provided... total users and OS
$users = array();
if ($results = $dbh->runQuery($sql)) {
foreach ($results as $key=>$row){
$users[$row['user_id']][] = array('user_id'=>$row['user_id'],
'email' => $row['email'],
'last_login' => $row['last_login'],
'fname' => $row['fname'],
'lname' => $row['lname'],
'role_id' => $row['role_id'],
'role_name' => $row['role_name'],
'os_d_token' => $row['os'],
'roid_d_token' => $row['roid'],
'p_name' => $row['p_name']);
}
}
Get total count of users
$user_cnt = count($row['user_id']);
Get total count of users with OS
$total_os = '';
if($row['os'] != null || '-1') {
$total_os = count($row['os']);
}
$resultsarray?$row['os']is not an array.. maybe use aCOUNTin the SQL query?$users[$row['user_id']][]... then you may be wantingcount($users)to find the end result of unique users?foreach, you can do that, and it should give you the count of users by unique user_id (as you have it). However getting count of unique OS would require a bit more like MattS's answer.