Edit array values [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Edit array values [SOLVED]

Post by aceconcepts »

I have the following array structure:

Array ( [0] => Array ( [1] => Array ( [0] => 1 [1] => 4 ) ) )

What I want to be able to do is add values to the third nested array.

How would I do this?
Last edited by aceconcepts on Wed Apr 09, 2008 10:50 am, edited 1 time in total.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Edit array values

Post by EverLearning »

if you want to add values to the third nested array, so it looks, for example, like this

Code: Select all

array
  0 => 
    array
      1 => 
        array
          0 => int 1
          1 => int 4
          2 => string 'asdfadsfa' (length=9)
          'test' => string 'testxxxx' (length=8)
 
do this:

Code: Select all

$array[0][1][] = 'asdfadsfa'; // if the key value doesn't matter 
$array[0][1]['test'] = 'testxxxx'; // if you want to set a specific key
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Edit array values

Post by aceconcepts »

Nice one, i'll give it a whirl :D
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Edit array values

Post by aceconcepts »

It worked - excellent.

Thank you.
Post Reply