Possible Duplicate:
PHP get index of last inserted item in array
My array is generated the following way:
$_SESSION['add_fail_urls'][] = $_REQUEST['url'];
How do I get a number value of the automatically assigned key []?
Possible Duplicate:
PHP get index of last inserted item in array
My array is generated the following way:
$_SESSION['add_fail_urls'][] = $_REQUEST['url'];
How do I get a number value of the automatically assigned key []?
<?php $numberOfFailedUrls = count($_SESSION['add_fail_urls']); ?>
Should do the trick. If you want to ensure that you don't get any notices about the add_fail_urls not existing, then use the following instead:
<?php
$numberOfFailedUrls = isset($_SESSION['add_fail_urls']) ?
count($_SESSION['add_fail_urls']) :
0;
?>
Edit: I might've misinterpreted your post (as of @des comment), as you might want the actual index of the added element instead of the number of elements. If so, here's a solution brought to you from @romaninsh in the linked question:
<?php
end($a);
$last_id=key($a);
?>