3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function createFunction($formula, $args) { $func = function ($args) use ($formula) { foreach ($args as $key => $val) { $$key = $val; } return eval($formula); }; return $func($args); } } $foo = new Foo; $formula = <<<'EOT' if($a == 'some_value' || $c == 'other_value') { return 'something'; } else if($b == 'something' && $d == 'anything') { return 'something_else'; } else { return 'anything'; } EOT; echo $foo->createFunction($formula, ['a' => 'some_value', 'b' => '', 'c' => 'other_value', 'd' => 'anything']); echo "\n"; echo $foo->createFunction($formula, ['a' => '', 'b' => 'something', 'c' => '', 'd' => 'anything']); echo "\n"; echo $foo->createFunction($formula, ['a' => '', 'b' => '', 'c' => '', 'd' => '']);
Output for git.master_jit, git.master, rfc.property-hooks
something something_else anything

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:
66.81 ms | 401 KiB | 8 Q