Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP array

Posted on 2011-02-14
4
Medium Priority
?
252 Views
Last Modified: 2012-05-11
Hello,

I am trying to combine 2 array so I can Implode them together.
$new_array1 contains field names
$new_array2 contains values

example being
$new_array1 = array('id', 'username', 'password');
$new_array2 = array('1', 'tom', 'cat');

$combined_array = array_merge ($new_array1, $new_array2);

print_r($combined_array);

the output I get is:
Array ( [0] => id = [1] => username = [2] => alpha [3] => beta )

it links the array together, but it appends array 2 to array 1.
what I am trying to do is to link both arrays together so

the master array = the first element of array 1 and array 2.

please can someone explain this to me please.

regards,Gavin




$combined_array = array_merge ($new_array1, $new_array2);
print_r($combined_array);
0
Comment
Question by:GPB1983
[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
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34887379
Use an iterator like foreach to access the two arrays.  But you have to be absolutely certain that the arrays match the way you want them to!
// UNTESTED CODE
$new = array();
foreach ($array1 as $num => $key)
{
   $new[$key] = $array2[$num];
}

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 total points
ID: 34887396
From this and another question you posted here at EE, I think you might want to stop programming for a little while and get some foundation in how PHP works.  This book is very readable and has great examples.  Give yourself a month to work though it and you will be way ahead in the game.  It will not make you a pro but it will get you started in the right direction.  Now in its fourth printing, it has been a part of my professional library since Version One.
http://www.sitepoint.com/books/phpmysql4/
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 34887398
0
 
LVL 17

Accepted Solution

by:
Chris Harte earned 1200 total points
ID: 34887420
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.

660 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