Php 设置数组值时自动获取指定的键
可能重复:Php 设置数组值时自动获取指定的键,php,Php,可能重复: 我的数组按以下方式生成: $_SESSION['add_fail_urls'][] = $_REQUEST['url']; 如何获取自动分配键的数值[] <?php $numberOfFailedUrls = count($_SESSION['add_fail_urls']); ?> 编辑:我可能误解了你的帖子(关于@des comment),因为你可能想要添加元素的实际索引,而不是元素的数量。如果是的话: <?php $numberOfFail
我的数组按以下方式生成:
$_SESSION['add_fail_urls'][] = $_REQUEST['url'];
如何获取自动分配键的数值[]
<?php $numberOfFailedUrls = count($_SESSION['add_fail_urls']); ?>
编辑:我可能误解了你的帖子(关于@des comment),因为你可能想要添加元素的实际索引,而不是元素的数量。如果是的话:
<?php
$numberOfFailedUrls = isset($_SESSION['add_fail_urls']) ?
count($_SESSION['add_fail_urls']) :
0;
?>
<?php
end($a);
$last_id=key($a);
?>