Solved

How to Merge 2 Arrays?

Posted on 2010-08-24
5
326 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
5 Comments
 
LVL 51

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 51

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP delete contents of file- before writing to it 6 49
Problem with MySQL query - graph 3 22
PHP Curl Problem 10 31
Error in sql query statment. 20 38
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…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

713 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