Solved

How to Merge 2 Arrays?

Posted on 2010-08-24
5
330 Views
Last Modified: 2012-05-10
Hi, I've got 2 Arrays, one is Session and the other is post.

for example.

$_SESSION['data'];
$_POST['data'];

first I begin like so.

$_SESSION['data']=$_POST['data'];



now when I do this.

$_SESSION['data'].=$_POST['data'];

just get array array array array etc?

how I merge them?
0
Comment
Question by:eNarc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 53

Accepted Solution

by:
Huseyin KAHRAMAN earned 250 total points
ID: 33517544
try this

$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);
0
 
LVL 53

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 250 total points
ID: 33517555
check here for user comments for diffrent solutions, bug fixes...

http://php.net/manual/en/function.array-combine.php
0
 
LVL 1

Assisted Solution

by:bonjourjolie
bonjourjolie earned 125 total points
ID: 33518082
there is few ways to merge arrays.

1. array combine. 1 array will become row & other array will become Column
Ex:
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);
print_r($c);
Result;
Array
(    [green]  => avocado
    [red]    => apple
    [yellow] => banana)
*****************************************
2. array_merge. B array will become continues of A array.

$beginning = 'red';
$end = array(1 => 'yellow');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);

Array
    (   [0] => red
        [1] => yellow
    )
0
 
LVL 12

Assisted Solution

by:Avinash Zala
Avinash Zala earned 125 total points
ID: 33518121
JFI: ( . ) is used for string concatenation not for array..

0
 
LVL 5

Author Comment

by:eNarc
ID: 33541312
thankyou
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Session time out quickly. 6 46
PHP Curl Problem 10 66
assigning javascript variable to php variable 8 63
Can't find an open element in HTML 5 47
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question