Question

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?

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top