Can you share an example for the array you are handling ?
How to look up a value within an array with columns/key
I did a database search and it returned some data. I need to create a variable that takes only the team name and id. However, in this data that the bank returns to me, several lines repeat the same time. So I need to check if the time value already exists inside the array. But I'm not able to do it, because I'm creating a value assignment for each array.
I had done it that way, but the id was missing:
if(!in_array($value['title'], $teams)){
array_push($teams, $value['title']);
}
Now the way it has to be. But my verification is not correct, but I don't know how I can do this. Can anyone help me?
if(!in_array($value['title'], $teams)){
array_push($teams, ['title' => $value['title'], 'id' => $value['teams.id']]);
}
Almost complete code:
$teamsusers = TeamsUser::query();
$teamsusers = $teamsusers->join('users', function($query){
$query->on('teams_users.user_id', 'users.id')->where('users.status', 'active');
});
$teamsusers = $teamsusers->join('teams', function($query){
$query->on('teams_users.teams_id', 'teams.id')->where('teams.status', 'active');
});
$teamsusers = $teamsusers->select('teams_users.teams_id', 'teams_users.user_id', 'users.name', 'users.photo', 'teams.title');
$teamsusers = $teamsusers->get();
// Division of what was caught in other variables
$divisionTimes = [];
$teams = [];
foreach ($teamsusers as $key => $value) {
// Division times
$divisionTimes[$value['teams_id']]['teamName'] = $value['title'];
$divisionTimes[$value['teams_id']]['users'][$key] = [
'userName' => $value['name'],
'photo' => $value['photo'],
];
// Just the teams
if(!in_array($value['title'], $teams)){
array_push($teams, $value['title']);
}
}
Query http://stage.preparadao.com.br.s3.amazonaws.com/time.htm
Please or to participate in this conversation.