Answer the question
In order to leave comments, you need to log in
Question with Foreach, how to get a variable?
Hello, here is the code
$id = $this->database->all("customs"); - тут получаем все значения из таблицы
$key_all = array_column($id, 'user_id'); - из полученных значений вытаскиваем ключи
$keys = array_unique($key_all); - убираем ключи с дублирующими значениями
foreach ($keys as $key) {
$users = $this->database->whereAll("users", 'id', $key);
}
Answer the question
In order to leave comments, you need to log in
Well, you're smart :) You overwrite the value of the $users variable with each iteration of the loop. Declare this variable as an array, and instead of overwriting, append the values to the end. Like this:
$id = $this->database->all("customs"); //тут получаем все значения из таблицы
$key_all = array_column($id, 'user_id'); //из полученных значений вытаскиваем ключи
$keys = array_unique($key_all); //убираем ключи с дублирующими значениями
$users = array(); //Инициализируем массив с пользователями
foreach ($keys as $key) {
$users[] = $this->database->whereAll("users", 'id', $key); //Две скобочки решают
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question