Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义变量?但我定义了它_Php_Variables - Fatal编程技术网

Php 未定义变量?但我定义了它

Php 未定义变量?但我定义了它,php,variables,Php,Variables,在任何人声称有重复的问题之前。。。(我注意到,无法回答问题的人往往会跑着寻找重复的问题,然后报告。) 这是您要查找的副本: 然而,这并不是完全重复的。它给了我一个解决方案,但我不是真的在寻找这个特定的解决方案 我的问题是: 注意:未定义变量:自定义 下面是我的代码: $headers = apache_request_headers(); // Request the visitor's headers. $customhead

在任何人声称有重复的问题之前。。。(我注意到,无法回答问题的人往往会跑着寻找重复的问题,然后报告。)

这是您要查找的副本:

然而,这并不是完全重复的。它给了我一个解决方案,但我不是真的在寻找这个特定的解决方案

我的问题是:


注意:未定义变量:自定义

下面是我的代码:

                $headers = apache_request_headers(); // Request the visitor's headers.
                $customheader = "Header: 7ddb6ffab28bb675215a7d6e31cfc759"; //This is what the header should be.
                        foreach ($headers as $header => $value) { 
                                $custom .= "$header: $value"; 
}
显然,定义了$custom。根据另一个问题,它是一个全球性的,应该标记为一个。但它如何成为一个全球性的组织?我怎样才能使它成为一个(非全球性的)?该脚本工作正常,它仍然显示它应该显示的内容并正确操作,但是当我打开错误消息时,它也会简单地输出该通知。我想目前没有必要修复它,但我还是想修复它,并知道它为什么要这样做。

问题在于:

$custom .= "$header: $value"; 
您将附加到$custom,但在第一次运行循环之前,$custom中的值是未定义的


放置一个
$custom='',错误应该消失。

我没有看到
$custom
的初始定义-我看到您连接到它,但您从未给它一个初始值

放入一行
$custom=''在foreach循环之前