PHP find array keys

Posted by Jens Törnell on Stack Overflow See other posts from Stack Overflow or by Jens Törnell
Published on 2010-04-11T10:00:56Z Indexed on 2010/04/11 10:03 UTC
Read the original article Hit count: 202

Filed under:
|
|
|
|

In PHP I have an array that looks like this:

$array[0]['width'] = '100';
$array[0]['height'] = '200';
$array[2]['width'] = '150';
$array[2]['height'] = '250';
  • I don't know how many items there are in the array.
  • Some items can be deleted which explains the missing [1] key.

I want to add a new item after this, like this:

$array[]['width'] = '300';
$array[]['height'] = '500';

However the code above don't work, because it adds a new key for each row. It should be the same for the two rows above. A clever way to solve it?

An alternative solution would be to find the last key. I failed trying the 'end' function.

© Stack Overflow or respective owner

Related posts about array

Related posts about keys