jeudi 27 juillet 2017

Laravel's collection filter pass by reference not working

can you please help me in using closures. I'm using laravel's collection filter to check unique emails. The code below should fill the $unique_email array inside the filter function. Is there's a problem on how i used the pass by reference? Thanks in advance.

    $unique_email = array();

    $users->filter(function ($user) use (&$unique_email) {
        if( !in_array(   $user->email , $unique_email  ) ) {
            return $unique_email[] = $user->email;              
        }
    });

    dd($unique_email); //returns empty array



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ePnDfI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire