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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:04:23+00:00 2026-05-11T18:04:23+00:00

I want to quickly identify if a key is present in an array, to

  • 0

I want to quickly identify if a key is present in an array, to avoid throwing an error.

For example, I might have an array like this

$arr['f']['b']['g'] = array( 'a', 'b', 'c', ) ;

Or the array might not have any variables in $arr[‘f’][‘b’] at all:

$arr['f']['x'] = array() ;

How can I avoid repetition in a test when referencing the (perhaps) contents of $arr[‘f’][‘b’][‘g’]?

if ( isset( $arr['f'] ) &&
     isset( $arr['f']['b'] ) &&
     isset( $arr['f']['b']['g'] ) /* ... yawn */ ) {
  /* blah */
}

There must be a terser way to identify whether a given array value I’m referencing exists? It seems far too verbose to have to test for the presence of both the value I seek, and all its ancestry as well. In some circumstances that makes sense, yes, but not all.

By example: it might represent, say, user->session->cart, where I want a way to quickly check whether the cart has entries, without having to include a check each for whether the user exists, then whether the session exists, then whether the cart exists, then …

Edit: I’m not looking for “does an array value with a key name of ‘g’ exist”, as “does an array value with an ancestry of f => b => g exist”.

  • 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-11T18:04:24+00:00Added an answer on May 11, 2026 at 6:04 pm

    The following will work as you expect:

    if(isset($a['a']['b']['c']))
    

    If any of those elements are undefined, isset() will return false.

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

Sidebar

Related Questions

I have a large number of 2D points and I want to quickly get
I want to quickly identify all writable files in the directory. What is the
I want to be able to easily and quickly delete an array of needles
I want to learn quickly like in an few hours an automated testing tools.
I have some .png images and I want to be able to quickly: (a)
I have a legacy class that I quickly want to write a couple of
I want to find a way to develop database projects quickly in Visual Studio.
I just want a simple tool that will help me quickly write scripts/packages that
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I have several sites in different domains: example.com , example.org , mail.example.com and passport.example.org

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.