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 7819755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:04:05+00:00 2026-06-02T07:04:05+00:00

I have learned that isset($array) is not required when checking for existence of particular

  • 0

I have learned that isset($array) is not required when checking for existence of particular key, however I also know that there is some reasons to check, without known key, if $array is instantiated.

For example this:

foreach ($foo as $bar) {
    echo $bar;
}

PHP Notice: Undefined variable: foo
PHP Warning: Invalid argument supplied for foreach()

is better this way:

if (isset($foo)) {
    foreach ($foo as $bar) {
    echo $bar;
    }
}

As I use arrays a lot when dealing with data and I wanted to ask if there is some other cases where i should check if whole array isset()? Or should I just stick on checking every $array[$key] that I am going to use whenever known?
This relates to question if there is any advantages or disadvantages on doing this:

if (isset($foo[0])) {
    foreach ($foo as $bar) {
        // noop
    }
}

instead of this:

if (isset($foo)) {
    foreach ($foo as $bar) {
        // noop
    }
}

So, should I ever use isset($array) in place of isset($array[$key]) if $key is known?

  • 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-02T07:04:06+00:00Added an answer on June 2, 2026 at 7:04 am

    In PHP, isset() is a special form, not a function; when you call isset($ary[$index]), $ary itself doesn’t have to be set first. Even with E_STRICT, the call won’t generate a warning, because isset doesn’t actually try to access $ary[$index]; it gets as far as determining that $ary is not set and returns false. So you don’t need to check the array first in order to apply isset to an element.

    Your question indicates that you know this already, and are wondering if there’s a reason why you would do it anyway. The only thing I can think of is efficiency: if you’re going to be checking a large number of keys for existence in an array, you can save some work by first detecting when the array itself isn’t set, and just skipping all the individual key checks in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm required to write a JCE provider. I have learned that I need to
I have learned that Python 3 is not backwards compatible. Will it not affect
I have learned that python does not guarantee that __del__ is called whenever an
I have learned that Windows uses UTF-16LE on x86/x64 systems. What about Linux? Which
So I have learned that that the Microsoft.Jet.OLEDB.4.0 data provider for querying data sources
One CSS rule I have learned is that you should use the relative em
I have learned from various tutorial that If a client can reasonably be expected
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
I have learned so much from http://www.summerofnhibernate.com/ nhibernate screen casts that i wonder why
I have an application that stores images in a database. Now I have learned

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.