Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9059319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:56:43+00:00 2026-06-16T14:56:43+00:00

Possible Duplicate: PHP get index of last inserted item in array My array is

  • 0

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 []?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:56:45+00:00Added an answer on June 16, 2026 at 2:56 pm
    <?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);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP: how to get last inserted ID of a table? I'm writing
Possible Duplicate: PHP: how to get last inserted ID of a table? I made
Possible Duplicate: PHP: how to get last inserted ID of a table? This is
Possible Duplicate: PHP get both array value and array key I am using Codeigniters'
Possible Duplicate: PHP Built-in Method to Get Array Values Given a List of Keys
Possible Duplicate: Get PHP class property by string Is there a cleaner way to
Possible Duplicate: php string function to get substring before the last occurrence of a
Possible Duplicate: PHP convert nested array to single array while concatenating keys? Get array's
Possible Duplicate: How to redirect all requests to index.php and keep the other GET
Possible Duplicate: Url Rewriting Help How do I get a url ending in /index.php?p=2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.