[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 548
  • Last Modified:

Append to 2-Dimensional Array

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
jdana
Asked:
jdana
  • 2
2 Solutions
 
hieloCommented:
0
 
MacAnthonyCommented:
All you need to do is specify the first dimension first and it works like a normal array:

$fruits['fruits'][] = 'mango';
0
 
MacAnthonyCommented:
Or:

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

didn't notice it was an associative array at first.
0
 
jdanaAuthor Commented:
It's actually straight-forward.  Awesome!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now