Solved

How to Merge 2 Arrays?

Posted on 2010-08-24
5
325 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:
HainKurt 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:HainKurt
HainKurt 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 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