3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Condition { private $value; private $variable = false; public function setCondition($new_value) { switch ($new_value) { case 'cond2': $this->variable = true; break; case 'cond4': $this->variable = false; break; } $this->value = $new_value; } public function getCondition() { return $this->value; } public function isVariableSet() { return ($this->variable === true); } } $conditions = array( 'cond1', 'cond2', 'cond3', 'cond4','cond5' ); $cond = new Condition(); $results = array(); $setCondGetVariable = function($condition) use($cond) { $cond->setCondition($condition); if ($cond->isVariableSet() == true) { $toggle = 'on'; } else { $toggle = 'off'; } return $toggle.' ; '; }; $results = array_map($setCondGetVariable, $conditions); var_dump($results);

preferences:
44.8 ms | 402 KiB | 5 Q