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

  • Home
  • SEARCH
  • 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 7667609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:08:58+00:00 2026-05-31T15:08:58+00:00

While researching how to detect null values in an array , I came across

  • 0

While researching how to detect null values in an array, I came across some user’s comment under the http://www.php.net/manual/en/function.array-key-exists.php manual page.

It said that

if (isset(..) || array_key_exists(...))
{
...
}

is faster than doing

if array_key_exists(...))
{
...
}

The bench marks posted for 100000 runs were

array_key_exists() : 205 ms
is_set() : 35ms
isset() || array_key_exists() : 48ms

My question:

Is (isset(..) || array_key_exists(...)) faster than array_key_exists() ?
If so, why?

EDIT: In writing out this question I think I found my answer. I’ve decided to post the question anyway to see if my thinking is correct.

  • 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-05-31T15:09:00+00:00Added an answer on May 31, 2026 at 3:09 pm

    Which is faster depends on the array you are checking. If the array contains a value other than null, “”, or 0

    if (isset(..) || array_key_exists(...)){    
    }
    

    the above code will be faster, because isset will be checked then the code executed. Array_key_exists will not be run.

    If the array contains a value of null, “”, or 0 then isset will be tested and then array_key_exists.
    This will take longer than simply testing for array_key_exists by itself.

    So the question which is faster depends a lot on the array you are checking.

    A lot of people have said that it doesn’t really matter. They didn’t explain why it doesn’t matter though. I guess they mean that the speed improvements are so minimal that it isn’t worth bothering with. They may also mean that which is faster is dependent on the values assigned in your array (and thus different each time.)

    Ultimately though, if you know that most of the keys will be assigned values other than null, “” or 0 and you really need to determine when null values are assigned, then use

    if (isset(..) || array_key_exists(...)){    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While researching the issue of JSON vs XML , I came across this question
While researching Oracle Analytics, I came across this query: select an_id, a_date, min(a_date) over
Found this official ACS demo http://www.fabrikamshipping.com/ while researching on ACS. In the app itself,
While researching the use of Table Hints , I came across these two questions:
I came across this really nice looking Scala code while researching XMPP for a
While researching how to create custom compound views in Android, I have come across
I stumbled upon this post while researching on the Delete Directory options available under:
While Ctrl X works fine in vim under windows, Ctrl A selects all (duh).
I have a problem I have been researching for a while on the internet
While researching how to do cross-platform printf() format strings in C (that is, taking

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.