Merge Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Merge Array

Post by nitediver »

I have load data from two different table "prod & size", in push.php all data from chosen product push into array.
My question is, how to push the data from "size" along with the "prod"?
I wonder if I merge those two arrays.
Last edited by nitediver on Wed Jun 09, 2010 7:37 am, edited 1 time in total.
c_cicca
Forum Newbie
Posts: 2
Joined: Tue May 18, 2010 6:11 am

Re: Merge Array

Post by c_cicca »

Use the php function "array_merge()"

Example:

Code: Select all

<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
Output:
Array
(
[color] => green
[0] => 2
[1] => 4
[2] => a
[3] => b
[shape] => trapezoid
[4] => 4
)
Post Reply