3v4l.org

run code in 300+ PHP versions simultaneously
<?php function Query($str) { echo "$str\n"; } function Item_Search($AppID, $Keyword = '', $Wears) { // expected $Wears = [1,0,1,0,1] , numbers can be different from 0 to 1 $WearNames = ['red', 'green', 'blue', 'yellow', 'black']; $FinalWear = []; foreach ($Wears as $i => $Wear) { if ($Wear == 1) { $FinalWear[] = $WearNames[$i]; } } $FinalWear = "'" . implode("','", $FinalWear) . "'"; $EmptyWear = array_sum($Wears) == count($Wears) ? "OR wear = ''" : ''; $ItemList = Query(<<<EOD SELECT * FROM items WHERE appid=$AppID AND name LIKE '%$Keyword%' AND (wear IN ($FinalWear) $EmptyWear) EOD ); } Item_Search(4, 'shirt', [1, 0, 1, 0, 1]); Item_Search(13, 'shoe', [1, 1, 1, 1, 1]);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Optional parameter $Keyword declared before required parameter $Wears is implicitly treated as a required parameter in /in/DigL7 on line 7 SELECT * FROM items WHERE appid=4 AND name LIKE '%shirt%' AND (wear IN ('red','blue','black') ) SELECT * FROM items WHERE appid=13 AND name LIKE '%shoe%' AND (wear IN ('red','green','blue','yellow','black') OR wear = '')

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:
120.13 ms | 406 KiB | 5 Q