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("dodad_select", $select_options); ?> <input type="submit" name="submitdata" value="Update"> </form>
Output for 5.3.0 - 7.1.0
<form> Notice: Undefined index: dodad_select in /in/mfXE7 on line 20 Notice: Undefined index: dodad_select in /in/mfXE7 on line 20 Notice: Undefined index: dodad_select in /in/mfXE7 on line 20 <input type="submit" name="submitdata" value="Update"> </form>
Output for 4.3.0 - 5.2.17
<form> Notice: Undefined index: dodad_select in /in/mfXE7 on line 20 Notice: Undefined index: dodad_select in /in/mfXE7 on line 20 Notice: Undefined index: dodad_select in /in/mfXE7 on line 20 <input type="submit" name="submitdata" value="Update"> </form>