>我正在尝试创建一个可以应用并调用任何 php 文件的全局变量,但我无法显示声明的全局变量的输出值。这是我需要了解的方法的确切示例:
测试全局.php
<?php
session_start();
error_reporting(0);
?>
<html>
<head><title>Sum with Public Function</title></head>
<body>
<form action="output.php" method="post">
<input type="text" name="a">
<input type="text" name="b">
<input type="submit" value="Submit">
</form>
</body></html>
<?php
echo "";
$sums=$_POST['sums'];
if($sums){
global $d,$e,$c;
include('global-function.php');
get_instance();
$c=$d+$e;
}
?>
全局函数.php
<?php
function get_instance(){
$d = $_POST['a'];
$e = $_POST['b'];
}
?>
-和-
输出.php
<?php
global $d,$e,$c;
include('global-function.php');
get_instance();
echo "The First Number is: ".$d."<br />";
echo "The Second Number is: ".$e."<br />";
$c = $d + $e;
echo "The Sum is: ".$c;
?>
测试全局.php将显示表单。global-function.php 会将 $_post 的值存储到全局变量中。输出.php将处理并显示全局变量中存储的任何值。
提前感谢您的帮助...
在
函数中声明全局变量
function get_instance(){
global $d , $e ;
$d = $_POST['a'];
$e = $_POST['b'];
}