472,119 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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 36833
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.