Technically speaking, you don't even need the loop. You can simply insert all the values in one single array:
$query = 'INSERT INTO data (amount) VALUES ';
$valueSets = array_fill(0, count($prices), '(?)');//creates an array containing a (?) string for each price
$pdo = new PDO($dsn, $user, $pass, $attr);
$query .= implode(', ', $valueSets);//concatenate onto query string
$stmt = $pdo->prepare($query);
$stmt->execute($prices);
That's all. Of course, that's not a very nice way to do things, so I'd probably use something like this:
$stmt = $pdo->prepare('INSERT INTO data (amount) VALUES (:price)');
foreach ($prices as $price) {
$stmt->execute([':price' => $price]);
$stmt->closeCursor();//optional
}
Or, if you really want to use Mysqli:
$stmt = $link->prepare('INSERT INTO data (amount) VALUES (?)');
$price = null;
$stmt->bind_param('i', $price);//bind by reference
foreach ($prices as $price) {
$stmt->execute();//insert price
}
But honestly: this, to me looks like DB fixture related things. I'd simply put the prices in a CSV file or something, and then run a LOAD DATA LOCAL INFILE
query instead of writing a script to insert all the values