$clear = [];
for ($i = 1; $i <= 10; $i++) {
$clear[] = [
'mesto' => $i,
];
}
$mesta2 = \DB::table('mesta')->where('game_id', 595)->get();
$mesta2 = \DB::table('mesta')
->where('game_id', $gameId)
->join('users', 'mesta.user_id64', '=', 'users.id64')
->select(['mesta.*','users.username as username','users.avatar as avatar'])
->get();
$clear = [];
for ($i = 1; $i <= $game->mest_all; $i++) {
$find = 0;
foreach($mesta2 as $mestos) {
if($find == 0) {
if($mestos->mesto == $i) {
$find++;
$i++;
$clear[] = $mestos;
}
}
}
$clear[] = [
'mesto' => $i,
];
}
$mesta = json_encode($clear);
$clear = ...;
$mesta2 = ...;
$result = array_merge($clear, $mesta2->toArray())
$clear = [];
for ($i = 1; $i <= 10; $i++) {
$clear[] = [
'mesto' => $i,
];
}
$mesta2 = \DB::table('mesta')->where('game_id', 595)->get()->keyBy('mesto');
$result = \Illuminate\Support\Collection::make($clear)->map(function ($item) use ($mesta2) {
if ($persistedItem = $mesta2->get($item['mesto'])) {
return $persistedItem;
}
return $item;
});