3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildQuery($retrievables, $table, $conditions = "", $limit = 0, $order = "") { $query = "SELECT $retrievables FROM $table"; // if we have conditions - add them to the query $query .= ($conditions != "" ? " WHERE " . $conditions : ""); // if we have a limit - add it to the query $query .= ($limit != 0 ? " LIMIT " . $limit : ""); // if we have to order the results - add it to the query // first we create a "dictionary" which translates $niceValues that are used throughout the code // to $realValues which are used in the MySQL database // since the $realValues are different in every table - we must account to that switch ($table) { case 'users': $niceValues = ["userID", "userName", "userAge", "userLocation", "userSex", "userIntention", "usersTable"]; $realValues = ["uid", "uname", "user_bdate", "user_from", "name", "user_intrest", "nuke_users"]; // yeah - the field "name" is really the sex of the user break; case 'users': $niceValues = ["articleID", "articleTitle", "articleLeadingText", "articleBodyText"]; $realValues = ["sid", "title", "hometext", "bodytext"]; break; default: $realValues = []; } // we then replace $niceValues with $realValues $modifiedQuery = str_ireplace($niceValues, $realValues, $query); return $modifiedQuery; } print_r(buildQuery("userID, userAge, userSex", "usersTable", 10)); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $niceValues in /in/bZU2J on line 27 Deprecated: str_ireplace(): Passing null to parameter #1 ($search) of type array|string is deprecated in /in/bZU2J on line 27 Fatal error: Uncaught TypeError: str_ireplace(): Argument #2 ($replace) must be of type string when argument #1 ($search) is a string in /in/bZU2J:27 Stack trace: #0 /in/bZU2J(27): str_ireplace('', Array, 'SELECT userID, ...') #1 /in/bZU2J(31): buildQuery('userID, userAge...', 'usersTable', 10) #2 {main} thrown in /in/bZU2J on line 27
Process exited with code 255.

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:
70.49 ms | 402 KiB | 8 Q