php - Warning: array_merge(): Argument #1 is not an array, when processing two $_POST

840

I'm receiving the following error Warning: array_merge(): Argument #1 is not an array when processing$_POST['cpl'], although$_POST['add'] works fine

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']);
}
383

Answer

Solution:

That's because$cp is a string (you explicitly defined it that way).

$cp = ''; // <-- empty string
$cp = array_merge($cp, $_POST['cpl']);

should be:

$cp = array(); // <--now it's an array
$cp = array_merge($cp, $_POST['cpl']);
554

Answer

Solution:

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 witharray() instead.

People are also looking for solutions to the problem: PHP / MySQL SELECT Query and order by field (value1, value2) etc

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.