gpt4 book ai didi

php $_POST 使用 $$ 调用

转载 作者:行者123 更新时间:2023-12-02 06:42:13 26 4
gpt4 key购买 nike

我知道在 php 中可以使用以下代码:

$dog = 'Woof!';
$cat = 'Miauw!';
$animal = 'dog';
var_dump($$animal);

输出:“汪!”

当然,这是我的实际代码的简化示例,但您明白了。现在我似乎无法让 $_POST 变量以相同的方式运行。

例子:

$method = '_POST';
$$method['password'] = array();
// In the end i would want this piece of code above to do what i typed below
$_POST['password'] = array();

输出:'注意: undefined variable :_POST'

这是否意味着不可能以这种方式调用 $_POST 还是我做错了?

最佳答案

来自 php manual :

Note: Variable variables Superglobals cannot be used as variable variables inside functions or class methods.

关于php $_POST 使用 $$ 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5803876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com