1
$email_users[] = $row;

print_r($email_users);

Result:

Array ( 

[0] => Array ( 
[user_id] => 87436 
[username] => Admin 
[user_email] => email@online.us 
[user_lang] => de 
[allowed] => 1 ) 

[1] => Array ( 
[user_id] => 68013 
[username] => Testuser 
[user_email] => email2@online.us 
[user_lang] => de 
[allowed] => 1 ) 

[2] => Array ( 
[user_id] => 68013 
[username] => Testuser 
[user_email] => email2@online.us 
[user_lang] => de 
[allowed] => 1 ) 

)

As you can see, the user_id 68013 is double. I have to remove the double Array. The Result should look like this:

Array ( 

[0] => Array ( 
[user_id] => 87436 
[username] => Admin 
[user_email] => email@online.us 
[user_lang] => de 
[allowed] => 1 ) 

[1] => Array ( 
[user_id] => 68013 
[username] => Testuser 
[user_email] => email2@online.us 
[user_lang] => de 
[allowed] => 1 ) 

)

I read and tried several solutions I found on stack. For example:

How to get unique value in multidimensional array

$email_users[] = $row;

$user_ids = array();
foreach ($email_users as $h) {
$user_ids[] = $h['user_id'];
}
$email_users = array_unique($user_ids);

print_r($email_users);

But the print_r is only:

Array ( [0] => 87436 [1] => 68013 )

Thanks for your time.

Community
  • 1
  • 1
labu77
  • 605
  • 1
  • 9
  • 30

1 Answers1

0

You should get distinct value from your query. Use SELECT DISTINCT * FROM tablename and you will get Distinct value. Or use $email_users= array_unique($email_users, SORT_REGULAR);

Bharat Paudyal
  • 124
  • 1
  • 10