我使用下面的方式,想在不同的<?php?>标签内共用变量,但是实现不了,我也试过$_SESSION,也不可以做到。
<form method="get"> <input type="text" name="num1" placeholder="num1"> <input type="text" name="num2" placeholder="num2"> <button type="submit" name="submit" value="func1">提交</button></form>The result is: <?phpif (isset($GLOBALS['result'])) { echo "111"; echo $GLOBALS['result']; }?><?php$GLOBALS['result'] = 0;if(isset($_GET['submit']) && $_GET['submit'] == 'func1'){ $num1 = $_GET['num1']; $num2 = $_GET['num2']; $GLOBALS['result'] = $num1 + $num2; }?>
牧羊人nacy