It\'s as easy as the title sounds; I need to get the index/key of the last inserted item. Why is this difficult? See the following two code samples:
$a=array
You can use key($a) together with end($a)
$a=array();
$a[]='aaa'; foo($a);
$a[3]='bbb'; foo($a);
$a['foo']='ccc'; foo($a);
$a[]='ffffd'; foo($a);
function foo(array $a) {
end($a);
echo 'count: ', count($a), ' last key: ', key($a), "\n";
}
prints
count: 1 last key: 0
count: 2 last key: 3
count: 3 last key: foo
count: 4 last key: 4