473,382 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 36916
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2:...
1
by: Pratap Das | last post by:
Hi all, Is there any concept of bit arrays and routines to manipulate them in C? Basically I need to form bit arrays of different sizes eg: 5 bits , 6 bits etc and then interpolate the bits of...
5
by: Troy | last post by:
Hello, I have a dumb question. I have two array objects of type double with 12 elements in each object. I'd like to add the two objects but dont know how to. Any ideas? thanks
5
by: cody | last post by:
Hi, I have multiple Collections which I want to iterate over *without* copying alle my collections into one. If there is no method to do this I propose a new Class Enumerate which should provide...
1
by: jpoloney | last post by:
I was wondering if there was a quick and easy way to sort multiple arrays in C++. What I mean is that, say I have 3 integer arrays. They are in order by array indices (array1 corresponds to array2...
5
by: Ian Davies | last post by:
Hello I am trying to update a session, ie everytime the page is resubmitted I want the current selected value from a list to be appended to the old session value. I have the following code but am...
3
by: Schroeder, AJ | last post by:
Hello group, I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco...
4
by: selam | last post by:
I have this assignment using c++ please help me in writing a code. Suppose you have a main ( ) with three local arrays, all the same size and type (say float). The first two are already initialized...
3
by: atiq | last post by:
I am tyring to join two join fields together in a Report in the follwoing format: Date: Time: i have attempted this using the following code, but doesnt work: ="Date:" & " " & & " " &...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.