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 '<br>'; echo getSql(array('a', 'b')); // two choices echo '<br>'; 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) <br>SELECT id FROM table1 WHERE 'a' IN (cat1, cat2, cat3) AND 'b' IN (cat1, cat2, cat3) <br>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:
42.01 ms | 401 KiB | 8 Q