<?php
// $mysqli is already declared as a working database connection by this sandbox
$ids = [1, 5, 18, 25];
$names = ['Dave', 'Bill'];
$idCount = count($ids);
$nameCount = count($names);
$sql = 'SELECT name FROM somewhere';
$idPlaceholders = implode(',', array_fill(0, $idCount, '?'));
$namePlaceholders = implode(',', array_fill(0, $nameCount, '?'));
$ids = array(1,5,18,25);
// creates a string containing ?,?,?
$bindClause = implode(',', array_fill(0, count($ids), '?'));
//create a string for the bind param just containing the right amount of s
$bindString = str_repeat('s', count($ids));
echo $bindString . "\n";
$stmt = $mysqli->prepare("$sql WHERE id IN ($idPlaceholders) AND name IN ($namePlaceholders)");
$stmt->bind_param(str_repeat('s', $idCount + $nameCount), ...array_merge($ids, $names));
$stmt->execute();
$result = $stmt->get_result();
foreach ($result as $row) {
echo "<div>{$row['name']}</div>\n";
}