3v4l.org

run code in 300+ PHP versions simultaneously
<?php $idx = [[1,10],[2,4],[3,5]]; $x = array_column($idx,0); $y = array_column($idx,1); $string_y = ''; $string_x = ''; if(count($x) == count($y)){ $i = 0; foreach($x as $key => $value){ if ($key === array_key_last($x)) { $string_y .= $y[$key]; $string_x .= $x[$key]; }else{ $string_y .= $y[$key] . ','; $string_x .= $x[$key] . ','; } } $sql = "SELECT id, b1, b2 FROM dlt WHERE b1 IN ($string_x) AND b2 IN ($string_y) ORDER BY id DESC LIMIT 1"; echo $sql; }
Output for 7.4.28, 8.1.23 - 8.1.33, 8.2.10 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
SELECT id, b1, b2 FROM dlt WHERE b1 IN (1,2,3) AND b2 IN (10,4,5) ORDER BY id DESC LIMIT 1

preferences:
77.19 ms | 406 KiB | 5 Q