3v4l.org

run code in 500+ PHP versions simultaneously
<?php function tableName () { return 'table_name'; } function select (array $columns, array $where) { for ($i = 0; $i < count($where); $i++){ $conditions[] = $where[$i][0] . ' ' . $where[$i][1] . ' :' . $where[$i][0]; $params[] = $where[$i][2]; } $sql = implode(" AND ", array_map(fn($cond) => "$cond", $conditions)); $columns = implode(", ",array_map(fn($att) => "$att",$columns)); echo "SELECT $columns FROM ".tableName()." WHERE $sql"; } $arrayCol = ["username","email"]; $arrayWhere = [["id", ">", 3], ["firstname", "=", "John"]]; select($arrayCol,$arrayWhere); ?>
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.7
SELECT username, email FROM table_name WHERE id > :id AND firstname = :firstname

preferences:
106.85 ms | 1264 KiB | 4 Q