Solved

Append to 2-Dimensional Array

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checking CSRF token within a function 36 76
Why do people dis php? 5 50
UPDATE query not working in mysqli php 8 52
Checkout Page Input Field not aligned 1 23
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‚Ķ
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

803 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