Solved

Append to 2-Dimensional Array

Posted on 2008-10-21
4
537 Views
Last Modified: 2012-05-05
I can CREATE (and populate) a 2D array using something like this:

$fruits = array ( "fruits"  => array ( "a" => "orange",
                                       "b" => "banana",
                                       "c" => "apple"
                                       ),
                );

How the heck do I APPEND to an existing 2D array?

$fruits = array ( "fruits"  => array ( "a" => "orange",
                                       "b" => "banana",
                                       "c" => "apple"
                                       ),
                );

Open in new window

0
Comment
Question by:jdana
[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 82

Assisted Solution

by:hielo
hielo earned 100 total points
ID: 22772398
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 22772408
All you need to do is specify the first dimension first and it works like a normal array:

$fruits['fruits'][] = 'mango';
0
 
LVL 11

Accepted Solution

by:
MacAnthony earned 150 total points
ID: 22772419
Or:

$fruits['fruits']['d'] = 'mango';

didn't notice it was an associative array at first.
0
 

Author Closing Comment

by:jdana
ID: 31508555
It's actually straight-forward.  Awesome!
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

615 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