Solved

Append to 2-Dimensional Array

Posted on 2008-10-21
4
519 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to dynamically set the form action using jQuery.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now