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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:56:39+00:00 2026-05-23T21:56:39+00:00

I am a dead beginner with PHP and have been reading through ‘PHP for

  • 0

I am a dead beginner with PHP and have been reading through ‘PHP for the Web: Visual Quickstart Guide 4th Ed.’ by Larry Ullman and have a question regarding something I came across in the book.

At the end of each chapter he has a few questions for review and I am stuck on one of them and not sure if I have the correct answer or the correct train of though regarding it.

The question is as follows:

Without knowing anything about $var will the following conditional be TRUE or FALSE? Why?

if ($var = 'donut') {...

I am apt to say that it will be false because we don’t know if $var has been assigned the value donut yet within the program but I am not sure.

Can anyone help explain this to me so I can grasp this concept and feel confident about 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-05-23T21:56:40+00:00Added an answer on May 23, 2026 at 9:56 pm

    This conditional will always evaluate to TRUE because the value donut is assigned, and then the value of $var is returned to the if() statement. The assignment happens first.

    A successful assignment to a variable causes that variable to be returned immediately. A non-empty string is a "truthy" value, and is returned as such.

    If instead it was assigned as:

    if ($var = "") {}
    

    It would evaluate to FALSE, according to PHP’s boolean evaluation rules:

    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)
    

    Addendum

    Just to add, as a practical example of assignment inside a flow control conditional you probably see almost every day — the while() loop we typically use to retrieve a rowset from a MySQL result resource:

    while ($row = mysql_fetch_assoc($result)) {
      // executes this inner block as long as $row doesn't 
      // recieve a FALSE assignment from mysql_fetch_assoc()
      // reaching the end of its rowset
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most dead-tree books and web tutorials address Rails 1.X. I'm wondering if they are
I have the following dead simple elisp functions; the first removes the fill breaks
How would you go about dead code detection in C/C++ code? I have a
I noticed a new web service today called a Dead man's switch , which
I want a dead simple generic $_GET-vars validator, and don't have any desire to
I'd like a dead simple explanation of policy injection for less-informed co-workers. Where is
If its dead, is there a successor? For those who didn't know: The Network
I'm looking for a dead simple mailing list (unix friendly). Robustness, fine-grained configurability, enterprise-readiness
The Apple Developer Documentation (link is dead now) explains that if you place a
The keys ^¨~ ´` etc are dead keys on my swedish keyboard on Mac

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.