<?php
$str = 'UPDATE `list` set `item`=?,`type`=? WHERE (`id` = ?);';
$data = array(
'item' => '1',
'type' => 'Are you ok?'
);
$pos = 0;
$index = 0;
do {
$pos = strpos($str, '?', $pos);
if ($pos === false) {
break;
}
$binding = array_values($data)[$index%count($data)];
$replacement = is_numeric($binding) ? $binding : '"' . $binding . '"';
$str = substr_replace($str, $replacement, $pos, 1);
$pos += strlen($replacement);
$index++;
} while ($pos !== false);
echo $str;
- Output for 8.1.23 - 8.1.28, 8.2.5 - 8.2.19, 8.3.0 - 8.3.7
- UPDATE `list` set `item`=1,`type`="Are you ok?" WHERE (`id` = 1);
preferences:
47.29 ms | 402 KiB | 30 Q