3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /*自己的選項*/ $url[] = array('url' => 'http://tw.yahoo.com','option' => 'yahoo.tw'); $url[] = array('url' => 'http://cn.yahoo.com','option' => 'yahoo.cn'); ?> <html> <head> <script> function chglink() {document.getElementById("link").innerHTML = document.getElementById("addr").value;} function chgFrame() {document.getElementById("iframe1").src = document.getElementById("link").innerHTML;} </script> </head> <body> 自己的選項 <?php print_r($url);?> <hr> <table border="1"> <tr><td>有select表單</td></tr> <tr><td>php在table內<select id="addr" onchange="chglink();"> <?php foreach($url as $k => $v) echo '<option value="'.$v["url"].'">'.$v["option"].'</option>'; ?> </select></td></tr> <tr><td>會顯示url(<a id="link" href="#" onclick="chgFrame();"></a>),請點我控制iframe</td></tr> <tr><td><iframe id="iframe1" src="<?php echo $url[0]["url"];?>" width="600px" height="400px"></td></tr> </table> </body> </html>
Output for 4.3.0 - 7.2.0
<html> <head> <script> function chglink() {document.getElementById("link").innerHTML = document.getElementById("addr").value;} function chgFrame() {document.getElementById("iframe1").src = document.getElementById("link").innerHTML;} </script> </head> <body> 自己的選項 Array ( [0] => Array ( [url] => http://tw.yahoo.com [option] => yahoo.tw ) [1] => Array ( [url] => http://cn.yahoo.com [option] => yahoo.cn ) ) <hr> <table border="1"> <tr><td>有select表單</td></tr> <tr><td>php在table內<select id="addr" onchange="chglink();"> <option value="http://tw.yahoo.com">yahoo.tw</option><option value="http://cn.yahoo.com">yahoo.cn</option></select></td></tr> <tr><td>會顯示url(<a id="link" href="#" onclick="chgFrame();"></a>),請點我控制iframe</td></tr> <tr><td><iframe id="iframe1" src="http://tw.yahoo.com" width="600px" height="400px"></td></tr> </table> </body> </html>