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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:38:16+00:00 2026-06-15T11:38:16+00:00

I know the comparison operator of PHP is not 100% because of the automatic

  • 0

I know the comparison operator of PHP is not 100% because of the automatic type declarations.

I did some tests and found this code

<?php
function foo($answer) {
    if ($answer > 10) {
        return true;
    } else {
        return $answer;
    }
}
if (foo(11)) {
    echo "11 is bigger than 10<br />";
}        
if (foo(9)) {
    echo "9 is bigger than 10<br />";
}
?>

The output is:

11 is bigger than 10
9 is bigger than 10

Can someone explain me where and why the code fails in this comparison.

  • 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-15T11:38:18+00:00Added an answer on June 15, 2026 at 11:38 am

    Function foo() always returns some value. In this case both boolean and int type. Just make sure you are more strictly when you compare returned value.

    <?php
    function foo($answer) {
        if ($answer > 10) {
            return true;
        } else {
            return $answer;
        }
    }
    
    if (foo(11) === true) {
       // This returned TRUE 
       echo "11 is bigger than 10<br />";
    }
    
    if ( is_int(foo(9)) === true ) {
       //This returned int 
       echo "9 is bigger than 10<br />";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the names of most of the operators but not sure what operator<<
My string comparison is not working. I do not know why. It returns that
I did a few tests with strings using '=='. I know to compare strings
I know why this is not allowed: ulong x = 0xFEDCBA9876543210; long y =
I had a doubt on comparision operator in python. I would like to know
I know how function comparison works in Python 3 (just comparing address in memory),
I need to classify commercial products. You know what price comparison engines does. We
Anyone know where i can find a good comparison between the generally accepted Pro's
Does anyone know of a diff viewer or comparison program that can do paragraph-based
I have to do a comparison and I want to know which will be

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.