【发布时间】:2015-03-20 08:12:43
【问题描述】:
我有以下 PHP 代码,它存储在一个单独的 PHP 文件中,与我正在使用的 index.php 文件分开。
当不在函数中时,页面 include() 可以放入 index.php 文件中。
$_3_dart_score = $_POST["user-input"];
$remaining_score = 501 - $_POST["user-input"];
但是,当它包含在函数中时,它似乎不起作用。
<?php
function throw()
{
$_3_dart_score = $_POST["user-input"];
$remaining_score = 501 - $_POST["user-input"];
global $_3_dart_score
global $remaining_score
throw();
}
?>
我尝试了各种方法,甚至从 index.php 页面调用该函数,但似乎没有任何效果。
【问题讨论】:
-
你的函数正在调用自己,我非常怀疑你想要的
-
公平点。我会用循环再试一次。谢谢
-
你并不真正想要一个访问全局变量的函数。将它们作为参数传递,例如: function throw($input, $otherinput) {...