3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $select_options = array("foo"=>"bar", "foo2"=>"bar2", "foo3"=>"bar3"); function generateSelect($name = '', $options = array()) { $html = '<select name="'.$name.'">'; foreach ($options as $option => $value) { $html .= '<option value=' .'"' .$value . '"'. blah($name, "bar") . '>'.$option.'</option>'; } $html .= '</select>'; return $html; } function blah($varname, $varvalue) { if ($_POST[$varname] == $varvalue) { return " selected"; } } ?> <form> <?php generateSelect("", $select_options); ?> <input type="submit" name="submitdata" value="Update"> </form>
Output for 5.3.0 - 5.6.28, hhvm-3.10.0, 7.0.0 - 7.1.0
<form> Notice: Undefined index: in /in/cj199 on line 20 Notice: Undefined index: in /in/cj199 on line 20 Notice: Undefined index: in /in/cj199 on line 20 <input type="submit" name="submitdata" value="Update"> </form>
Output for hhvm-3.12.0
<form> Notice: Undefined index: in /in/cj199 on line -1 Notice: Undefined index: in /in/cj199 on line -1 Notice: Undefined index: in /in/cj199 on line -1 <input type="submit" name="submitdata" value="Update"> </form>
Output for 4.3.0 - 5.2.17
<form> Notice: Undefined index: in /in/cj199 on line 20 Notice: Undefined index: in /in/cj199 on line 20 Notice: Undefined index: in /in/cj199 on line 20 <input type="submit" name="submitdata" value="Update"> </form>