469,267 Members | 1,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

joining two arrays together

Hi,

I would like to join two arrays togther something like the following. I
don't know a simple way to create $stack3.

Thanks,
Peter

<?php

$stack1 = array("orange", "banana");
$stack2 = array("apple", "pear");

// do what for the next line?
$stack3 = ($stack1, $stack2);

print_r($stack3);
// The results I would like
// Array ( [0] => orange [1] => banana [2] => apple [3] => pear )

?>

Sep 14 '05 #1
4 36728
pe**********@yahoo.com schrieb:
$stack1 = array("orange", "banana");
$stack2 = array("apple", "pear");

// do what for the next line?
$stack3 = array_merge($stack1, $stack2);


Jo
Sep 14 '05 #2
if you have two similar keys in an associative array, you will have
problems : the values for one key is deleted by the values of the
ultimate similar key (see doc!).

Sep 14 '05 #3
ro**********@gmail.com schrieb:
if you have two similar keys in an associative array, you will have
problems : the values for one key is deleted by the values of the
ultimate similar key (see doc!).

your're right, but for the fuits in the example it works.
if you have similar keys you need your own function
because nobody knows what to do with those keys ...

ignore the first, discard the second, generate a new key, add the values
...

Jo
Sep 14 '05 #4
$stack3 = array_merge($stack1, $stack2);

Sep 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Phil Powell | last post: by
1 post views Thread by Pratap Das | last post: by
5 posts views Thread by Troy | last post: by
5 posts views Thread by cody | last post: by
1 post views Thread by jpoloney | last post: by
5 posts views Thread by Ian Davies | last post: by
3 posts views Thread by Schroeder, AJ | last post: by
4 posts views Thread by selam | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.