The essence is this, I extract a multidimensional array from the database, then I check for the presence of $ users ['tt'] ! In_array ($ i, $ users) , if there is such an id ($ users ['tt']) then I insert data if I don’t insert another block class = "number" with the current number $ i Ps.I'm sorry for the clumsy description.
//Массив взят через print_r $count_div = 50; //Сколько должно быть 50 блоков (Данные тоже берутся из бд) $users = Array ( [0] => Array ( [id] => 1 [gid] => 36 [tt] => 7 [user] => 2 [wr] => 0 [timestamp] => 0 [login] => demo [email] => demo@demo.dd ) [1] => Array ( [id] => 2 [gid] => 36 [tt] => 2 [user] => 3 [wr] => 0 [timestamp] => 0 [login] => demo1 [email] => demo@no.mail ) ) for( $i = 1; $i <= $count_div; ++$i ) { if( !in_array($i, $users) ){ $users[] = $i; echo '<div class="box"><div class="number">'.$i.'</div></div>'; }else{ echo '<div id="'.$user['tt'].'" class="box"><img src="'.$user['email'].'.jpg" alt="User '.$user['user'].'"></div>'; } }
in_arraywill not work, because in $ users only arrays, without values. A function with nested arrays does not work. Search function for nested arrays - here stackoverflow.com/questions/4128323/… - Alexey Shatrovarray_filterfunction. - And