3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $text = "foo { bar tree; bar ball/sand; snafu { string; } random { nested { value; bohica; } } }"; $buf = ""; $brace_level = 0; $words = array(); for ($i = 0; $i < strlen($text); $i++) { switch ($text[$i]) { case '{': $words[$brace_level] = trim($buf); $buf = ""; $brace_level++; break; case '}': unset($words[$brace_level]); $brace_level--; unset($words[$brace_level]); break; case ';': $words[$brace_level] = trim($buf); $buf = ""; ksort($words); print implode(" ", $words)."\n"; break; default: $buf .= $text[$i]; } }
Output for 4.3.0 - 7.1.0
foo bar tree foo bar ball/sand foo snafu string foo random nested value foo random nested bohica