Array Unique, not displaying some array after execution

I am using array_unique () to remove the duplicate value, but it gives me an error when the value comes from a string then converted using explode and the values ​​are not showing correctly

I am using http://phptester.net/ for testing

$email = 'general@t.com,info@t.com,info@t.com,jaa@t.com';

$emailList = array_unique(array_filter(array_map('trim',explode(',',$email))));

for($i = 0; $i < count($emailList); $i++){
    echo $emailList[$i];
}

      

+3


source to share


1 answer


I would do it like this:

$email = 'general@t.com,info@t.com,info@t.com,jaa@t.com';

$emailList = (array_map('trim',explode(',',$email)));

$result = array_unique($emailList);
var_dump($result);

      



If you want to print the values ​​of an array using a for-loop, you can do it like this:

$email = 'general@t.com,info@t.com,info@t.com,jaa@t.com';

$emailList = (array_map('trim',explode(',',$email)));

$result = array_unique($emailList);

for($i = 0; $i < count($emailList); $i++){
    if( $emailList[$i]!=null)
       echo $emailList[$i];
}

      

+1


source







All Articles