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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:47:10+00:00 2026-05-23T16:47:10+00:00

Possible Duplicate: Regarding if statements in PHP In PHP scripts – what does an

  • 0

Possible Duplicate:
Regarding if statements in PHP

In PHP scripts – what does an if statement like this check for?

<?php if($variable){ // code to be executed } ?>  

I’ve seen it used in scripts several times, and now I really want to know what it “looks for”. It’s not missing anything; it’s just a plain variable inside an if statement… I couldn’t find any results about this, anywhere, so obviously I’ll look stupid posting this.

  • 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-23T16:47:10+00:00Added an answer on May 23, 2026 at 4:47 pm

    The construct if ($variable) tests to see if $variable evaluates to any “truthy” value. It can be a boolean TRUE, or a non-empty, non-NULL value, or non-zero number. Have a look at the list of boolean evaluations in the PHP docs.

    From the PHP documentation:

    var_dump((bool) "");        // bool(false)
    var_dump((bool) 1);         // bool(true)
    var_dump((bool) -2);        // bool(true)
    var_dump((bool) "foo");     // bool(true)
    var_dump((bool) 2.3e5);     // bool(true)
    var_dump((bool) array(12)); // bool(true)
    var_dump((bool) array());   // bool(false)
    var_dump((bool) "false");   // bool(true)
    

    Note however that if ($variable) is not appropriate to use when testing if a variable or array key has been initialized. If it the variable or array key does not yet exist, this would result in an E_NOTICE Undefined variable $variable.

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

Sidebar

Related Questions

Possible Duplicate: Best practices regarding equals: to overload or not to overload? Does anyone
Possible Duplicate: PHP coding conventions? Are there any coding conventions regarding PHP? I'm looking
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Naming Boolean columns in Rails What is the rails convention regarding names
Possible Duplicates: Why does StyleCop recommend prefixing method or property calls with “this”? When
Possible Duplicate: Can anybody suggest the best image resize script in php? I'm still
Possible Duplicate: Does adding [Serializable] to the class have any performance implications? What is
Possible Duplicate: Benefits of inline functions in C++? I have a confusion regarding 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.