1

Having a bit of a problem in combining arrays...this works:

    $un[0] = array("0:0:0");
    //$un[1] = array("1:1:1");
    $flat = call_user_func_array('array_merge', $un);

If I uncomment the second $un, it still works (and combines the two).

Now, if I say, change that from a hard-coded array into an array from a DB query (I know mysql ext is being deprecated):

            $u = mysql_query("SELECT `XX` FROM `XX` WHERE `XX` = '".$XX."' AND `XX` = '0'");
            $un = mysql_fetch_row($u);

I run the query through PhpMyAdmin and it works. So when I add $flat = call_user_func_array('array_merge', $un); after the mysql_fetch_row it returns an error:

PHP Warning: array_merge() [function.array-merge]: Argument #1 is not an array in **LOCATION**

And I cannot seem to figure out why...since the DB query should spit out $un[0], $un[1], etc., exactly as the code that works, shouldn't it?

1 Answer 1

4

array_merge excepts one or more array's - what you actually do is to pass array_merge all cells of the row as an param. This looks i.e. like array_merge('row1', 'row2',...)

So what you want is perhabs something like this

$flat = call_user_func_array('array_merge', array($un));
Sign up to request clarification or add additional context in comments.

1 Comment

+1 you beat me and your explanation is a lot better then mine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.