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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:23:39+00:00 2026-06-08T00:23:39+00:00

When checking a superglobal like $_GET or $_POST for existence of a value for

  • 0

When checking a superglobal like $_GET or $_POST for existence of a value for a particular key, is there a method that encompasses the following functionality in a more concise way?

if (isset($_POST['foo']) && $_POST['foo'] !== '') {
    // ...
}

The isset() function by itself returns TRUE even when the value is an empty string '', so I can’t use that.

Using just $_POST['foo'] !== '' will work correctly by itself, but it emits an E_NOTICE for undefined index, which is undesirable.

The empty() function returns TRUE for the value "0", which is a valid value, so I can’t use that, either.

Am I missing something obvious, or is this really the best/only way to do it?

  • 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-08T00:23:41+00:00Added an answer on June 8, 2026 at 12:23 am

    Probably you are looking for array_key_exists():

    if (array_key_exists('foo', $_POST)){
        // will execute when $_POST['foo'] is set, even if to null, false, '' etc.
    };
    

    If you do not want to match empty string (''), then your solution is probably enough. Solution above gives you false only when the key does not exist.

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

Sidebar

Related Questions

Checking few RDBMS I find that things like SELECT COUNT (a), SUM (b) FROM
Is checking for key existence in HashMap always necessary? I have a HashMap with
I am checking whether Bluetooth is on or not using the following method; while
Checking the documentation online I saw that it is pass by reference. Can someone
Conditional Checking: if denominator == 0: // do something like informing the user, or
When checking that variables passed via GET and POST are correct, I might have
Checking out the following modules for connecting to mysql db: https://github.com/sidorares/nodejs-mysql-native http://github.com/felixge/node-mysql http://github.com/Sannis/node-mysql-libmysqlclient Do
When checking whether a particular browser supports AJAX, object detection is what I usually
I was checking out str objects in Python, and I realized that str object
While checking Mutex unlock codes around, I found some that add 1 into the

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.