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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:57:47+00:00 2026-06-12T19:57:47+00:00

I get input values via POST, some of them might be ID’s referring to

  • 0

I get input values via POST, some of them might be ID’s referring to other things, and some start at 0. When choosing something with ID 0, or something without a value, is there a method like intval() that returns something more helpful than 0 on failure to parse? Or can I somehow differentiate the result of intval() from the failure to parse?

Example:

echo intval(null); // 0
echo intval("0");  // 0
  • 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-12T19:57:48+00:00Added an answer on June 12, 2026 at 7:57 pm

    You can use the filter_var() function to determine the difference:

    filter_var(null, FILTER_VALIDATE_INT);
    // false
    
    filter_var('0', FILTER_VALIDATE_INT);
    // int(0)
    

    You can also add flags to specifically accept hexadecimal and octal values, but I wouldn’t recommend that for your case.

    Btw, in the more likely case that the variable comes from $_POST, you can also use filter_input():

    if (is_int($nr = filter_input(INPUT_POST, 'nr', FILTER_VALIDATE_INT))) {
        // $nr contains an integer
    }
    

    The reason I’m using is_int() on the result of filter_input is because when nothing is posted, null is returned; using is_int() guards against this issue.

    Edit

    If the question is really just about null vs '0' you can just compare $var !== null:

    if (!is_null($var)) {
        // $var is definitely not null
        // but it might also be an object, string, integer, float even, etc.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I only know how to get POST values via named elements, such as: <?php
How do i get the values of specific input elements inside the gform_after_submission hook
Can someone please let me know how to get values from several input fields?
How to set up a TextBox to get only certain values. e.g. DateTime input
i'm using div content editable html to get value from input keyboard to post
I am loading some text from a database via $.post. Sometimes on page load
I need to get neighborhood element value. HTML is <div> <input type='hidden' value='12345'> <div
document.forms[regform][fname].value; In java script i get the value of input having name(fname) which is
I am trying to get the value of the text in the input fields.
HTML Javascript question to get the selected value of a input-select I can use

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.