Adding elements to last element of array

arrays, php

Solution

If $myArray is not associative

array_push($myArray[count($myArray)-1]['list'], 'new element');

or

$myArray[count($myArray)-1]['list'][] = 'new element';

with this method you change the position of the array pointer.

Problem

If I have the following array. What would be the best way to add a element to `list[]` for the last element of `$myArray[]`? Note that `list[]` has numerical indexes (i.e. not associative). Thanks! ``` $myArray[] = array( 'name' => 'hello', 'list' => array() ); ```

Original source