ubee
ubee

Reputation: 27

PHP array of arrays: problem to push item on inner array

I would like to append elements to an array that is part of another array. I add an element to $aA in this way:

$aA[] = array('label'=>"string1",'data'=>array());

By this the array will be extended by new element with the following context in json notation:

{ index:'string1',data:{}}

The array referred to by 'data' is initially empty.

A bit later I would like to append/push the elements 1,2,3 to the 'data' array in the last element of $aA. I have tried with this:

end($aA)['data'][]=1;
end($aA)['data'][]=2;
end($aA)['data'][]=3;

with the following expected content of the last element i $aA

{ index:'string1',data:{1,2,3}}

But this doesn't work. The array referred to by 'index' is still empty.

How should I do this to make it work?

Upvotes: 0

Views: 99

Answers (1)

Combinu
Combinu

Reputation: 907

How about you use array_push?

array_push($aA['data'], 1);

PHP: array_push

Upvotes: 1

Related Questions