3v4l.org

run code in 300+ PHP versions simultaneously
<?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.33, 8.2.5 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
UPDATE `list` set `item`=1,`type`="Are you ok?" WHERE (`id` = 1);

preferences:
91.54 ms | 406 KiB | 5 Q