473,568 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

joining two arrays together


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



$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 36924
pe**********@ya hoo.com schrieb:
$stack1 = array("orange", "banana");
$stack2 = array("apple", "pear");

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

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**********@gm ail.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

Sep 14 '05 #4
$stack3 = array_merge($st ack1, $stack2);

Sep 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2: The name of the second array $formField1CompareWith: String to use as my comparison basis for first array. Defaults to using $val unless it's 'key'...
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 these arrays together to form a big array...ie some kind of bit interleaving. What is the most efficient way to do that in C? If I use uint8 etc then...
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
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 something like that: IEnumerable Join(IEnumerable a,IEnumerable b)
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 and array3, etc). I want to do something exactly like the Excel sort of "Sort by A, then by B, then by C". Meaning, sort array A in ascending...
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 unable to get it to work. I dont know the correct syntac wher I have put the word 'PLUS'. <?php $_SESSION = $_SESSION PLUS $_POST;?> I have...
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 router in which I expect the script to return the interface number along with a small description of the interface type, like this: Array (
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 to values. Write a function called add arrays ( ) that accepts the addresses of the three arrays as arguments; add the contents of the first two...
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:" & " " & & " " & "Time:" & " " &
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.