Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

appending an array to an array

Status
Not open for further replies.

kubla

Programmer
Feb 7, 2002
50
IT
I wonder if it's possible to append an array to an array without looping through individual records?

Specifically, if a function returns an array such as:

$varname = function(foo);

how can I append the results of function(bar) to $varname without overwriting the results of function(foo)?

Any suggestions would be greatly appreciated.
 
hello ,
i dont understand exactly what u want to do ,
but to append to arrays u can make use of php function
array_merge(array1,array2)and it will return an array with array1 appeneded by array2.
some key values then that wil get appened by the second array.

regards

spookie
 
well, to be more specific, I have to seperate queries:

$first_result = mysql_query($first_query);
$second_result = mysql_query($second_query);

I need to pass both $first_result and $second_result to a script which parses the results.

Since the structure of both results is identical, rather than loop, I want to merge to the two results in the manner of:

$results = $first_result + $second_result;

or, as you've suggested:

$results = array_merge ($first_result, $second_result);

only neither works. At least, if they do, then the array which they're returning is no longer comprehensible to my script which works if it receives the array $first_result or $second_result.

I've been reading up here:


again, things should work, but they don't seem to.

Any further advice or suggestions on how to deal with this would be most welcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top