PHP函数与第二个参数/参数混淆
在所有脚本结束时,我运行一个函数PHP函数与第二个参数/参数混淆,php,function,arguments,Php,Function,Arguments,在所有脚本结束时,我运行一个函数closeConnection,即: closeConnection("success"); function closeConnection($note) { if ($note === "success") { $append = "?success"; } if ($note === "blank") { $append = "?blank"; } mysql_close(); header("Location: index
closeConnection
,即:
closeConnection("success");
function closeConnection($note) {
if ($note === "success") { $append = "?success"; }
if ($note === "blank") { $append = "?blank"; }
mysql_close();
header("Location: index.php" . $append . "");
exit();
}
运行平稳
但是,我现在希望我的closeConnection()
函数接受两个参数,这样我就可以选择要重定向到的不同页面。这是它第二次出现时的样子:
closeConnection("updated", "view");
function closeConnection($note, $header) {
$header = $header; // Not sure if needed, doesn't work with or without.
if ($note === "updated") { $append = "?updated"; }
if ($note === "blank") { $append = "?blank"; }
mysql_close();
header("Location: " . $header . ".php" . $append . "");
exit();
}
所需结果:重定向到view.php?已更新
实际结果:重定向到.php?blank
根据我的经验,您正在调用closeConnection(“更新”)代码>关闭连接之前的某个地方(“更新”、“查看”)代码>但你忘了删除它或其他东西
确保您没有忘记以前的命令,并且您实际上保存了正确的文件。是您的实际结果“.php?blank”还是“.php?”如果没有以任何方式进行设置,您为什么希望看到更新的?如果您通过success
,则唯一的可能性是?success
<代码>?如果您通过blank
则为空,或者如果您通过其他任何内容(例如查看
)$header=$header,则为空代码>???$header=$header代码>=>不需要这样做;)对不起,从我的代码中复制了错误的if
语句(有很多)。正确的一个应该在那里了。并且,$header=$header
存在,因为我不确定是否需要“拉入”函数的参数。。。这些对我来说都是新的。实际结果是.php?空白