3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keys = array('SELECT','FROM','WHERE','LEFT','ORDER'); $sql = "Select id, nome FROM table as t WHERE t.id = 123 LEFT JOIN t2 ON t2.id = t.id ORDER BY t.name "; $str = preg_replace('!\s+!', ' ', $sql); $arr = explode(' ', $str); $j = -1; $out = []; for ($i = 0; $i < count($arr); $i++) { if (in_array(strtoupper($arr[$i]), $keys)) { if(($kw = array_search(strtoupper($arr[$i]), $keys)) !== false) { unset($keys[$kw]); } $j++; $out[$j][0] = $arr[$i]; $out[$j][1] = ''; continue; } if ($j > -1) { $out[$j][1] = $out[$j][1] . $arr[$i] . ' '; } } var_dump($out);
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { [0]=> array(2) { [0]=> string(6) "Select" [1]=> string(9) "id, nome " } [1]=> array(2) { [0]=> string(4) "FROM" [1]=> string(11) "table as t " } [2]=> array(2) { [0]=> string(5) "WHERE" [1]=> string(11) "t.id = 123 " } [3]=> array(2) { [0]=> string(4) "LEFT" [1]=> string(24) "JOIN t2 ON t2.id = t.id " } [4]=> array(2) { [0]=> string(5) "ORDER" [1]=> string(11) "BY t.name " } }

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