3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSql($arr) { $sql = 'SELECT id FROM table1 WHERE '; $and = ''; foreach ($arr as $a) { $sql .= $and . "'$a' IN (cat1, cat2, cat3) "; $and = ' AND '; } return $sql; } echo getSql(array('a')); // one choice echo "\n"; echo getSql(array('a', 'b')); // two choices echo "\n"; echo getSql(array('a', 'b', 'c')); // three choices ?>
Output for git.master, git.master_jit, rfc.property-hooks
SELECT id FROM table1 WHERE 'a' IN (cat1, cat2, cat3) SELECT id FROM table1 WHERE 'a' IN (cat1, cat2, cat3) AND 'b' IN (cat1, cat2, cat3) SELECT id FROM table1 WHERE 'a' IN (cat1, cat2, cat3) AND 'b' IN (cat1, cat2, cat3) AND 'c' IN (cat1, cat2, cat3)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.78 ms | 402 KiB | 8 Q