<?php
// $mysqli is already declared as a working database connection by this sandbox
$ids = [1, 5, 18, 25];
$idCount = count($ids);
$sql = 'SELECT name FROM somewhere WHERE id IN ($idPlaceholders)';
$idPlaceholders = implode(',', array_fill(0, $idCount, '?'));
$stmt = $mysqli->prepare($sql);
$stmt->bind_param(str_repeat('s', $idCount), ...($ids));
$stmt->execute();
$result = $stmt->get_result();
foreach ($result as $row) {
echo "<div>{$row['name']}</div>\n";
}