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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:07+00:00 2026-05-27T04:49:07+00:00

This if else statement does not work: (in this situation it displays ‘x is

  • 0

This if else statement does not work: (in this situation it displays ‘x is euqal to null’)

<?php

$x = 0;

if ($x == 'null'){
    echo 'x is euqal to null';}

else if ($x == 0){
    echo 'x is equal to zero!';}

else if ($x == 1){
    echo 'x is equal to one!';}

?>

My reason for needing this is that I am writing a quiz program, and one of the features is that it displays a tick, cross or three dots next to each question depending on whether the user has done it and what their score is.

If the score for that question = ‘null’ then they haven’t yet done it ( display …)
If the score for that question = 1 then they have done it, and got it right (display tick)
If the score for that question = 0 then they’ve none it, but got it wrong (display cross)

My actual code is:

$score = ($_SESSION['score']);       
         if ($score[$questionList[$loop]['ID']]=='null'){ ?>
             <p style="display:inline;"> ...  </p> <?php } 
         else if ($score[$questionList[$loop]['ID']]==1){ ?>
             <p style="display:inline;"> &#10003  </p> <?php }      
        else if ($score[$questionList[$loop]['ID']]==0){ ?>
             <p style="display:inline;"> X  </p> <?php }  ?>  

Although it’s part of a much bigger page.

I am quite new to PHP, so am probably being incredibly thick here, but any suggestions will be much appreciated, thanks : )

  • 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-27T04:49:07+00:00Added an answer on May 27, 2026 at 4:49 am

    I believe the first condition returns true because strings are equal to 0. See documentation on comparison operators.

    The solution is to replace your == with ===. Ex:

    <?php
    
    $x = 0;
    
    if ($x === 'null'){
        echo 'x is euqal to null';}
    
    else if ($x === 0){ \\true
        echo 'x is equal to zero!';}
    
    else if ($x === 1){
        echo 'x is equal to one!';}
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a if statement that does not work, it doesn't check its condition
I am executing this statement under while (($data=fgetcsv($this->fin,5000,;))!==FALSE) Now what I want in else
I can't seem to get my php script to send email. <?php echo Does
Switch statements are typically faster than equivalent if-else-if statements (as e.g. descibed in this
Example: public bool Save(MyObj instance) { if (instance.IsNew) { this.repository.Create(instance); } else { this.repository.Update(instance);
Anyone else get this or suffer from this? I am using Vista and VS
Has anyone else had this issue and found a working solution? I've enabled the
has anyone else experienced this . I have SP1 but i have to kill
Has anyone else experienced this? I have uninstalled and reinstalled TortoiseSVN as well as
This should be easy (at least no one else seems to be having a

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.