php 警告:array_merge():当处理两个 $_POST 时,参数 #1 不是数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18705733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: array_merge(): Argument #1 is not an array, when processing two $_POST
提问by acctman
I'm receiving the following error Warning: array_merge(): Argument #1 is not an arraywhen processing $_POST['cpl']
, although $_POST['add']
works fine
我收到以下错误警告:array_merge(): Argument #1 is not an arraywhen processing $_POST['cpl']
,虽然$_POST['add']
工作正常
if (is_array($_POST['add'])) {
foreach ($_POST['add'] as $key => $value) $_POST['add'][$key] = mysql_real_escape_string($value);
$en = array_merge($en, $_POST['add']);
}
if (is_array($_POST['cpl'])) {
foreach ($_POST['cpl'] as $key => $value) $_POST['cpl'][$key] = mysql_real_escape_string($value);
$cp = '';
$cp = array_merge($cp, $_POST['cpl']);
}
回答by John Conde
That's because $cp
is a string (you explicitly defined it that way).
那是因为$cp
is 是一个字符串(您以这种方式明确定义了它)。
$cp = ''; // <-- empty string
$cp = array_merge($cp, $_POST['cpl']);
should be:
应该:
$cp = array(); // <--now it's an array
$cp = array_merge($cp, $_POST['cpl']);
回答by Sven
You have these lines:
你有这些行:
$cp = '';
$cp = array_merge($cp, $_POST['cpl']);
It's self-explanatory: $cp
is a string first, the error is simply about this fact. Initialize it with array()
instead.
这是不言自明的:$cp
首先是一个字符串,错误只是关于这个事实。用array()
代替初始化它。