after array crunch i get array likes this [[10,9,7],[6,5,4],[3,1]] , but i want to foreach loop for all elements of array
Here is my code , i want foreach loop for all element of arrays
$all_users = \App\User::orderBy('id','desc')->pluck('id')->toArray();
$all_user = array_chunk($all_users, 3);
foreach($all_user as $numbers){
foreach($numbers as $number){
return $all_firebase_tokens = \App\UserDeviceId::WhereIn('user_id',$number)->pluck('firebase_token')->toArray();
}
}
Solution 1:
As Jaquarh mentioned, the very first iteration of the foreach loop will stop the whole function by already returning a value. Assuming what you need is an array of the firebase_tokens, something like this is likely what you need:
$all_users = \App\User::orderBy('id','desc')->pluck('id')->toArray();
$all_user = array_chunk($all_users, 3);
$all_firebase_tokens = [];
foreach($all_user as $numbers){
foreach($numbers as $number){
array_push($all_firebase_tokens, \App\UserDeviceId::WhereIn('user_id',[$number])->pluck('firebase_token')->toArray());
}
}
return $all_firebase_tokens;