InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

PHP

    PHP strings

    • PHP - split string examples
    • PHP - take last n characters of a string
    • PHP check if string contains something

    PHP Array

    • PHP - associative array value in double quoted string
    • PHP - check if a value is in array
    • PHP - convert array to associative array
    • PHP - print array in one line
    • PHP array foreach - code snippets
    • PHP array map example
    • PHP check if key exists in array
    • PHP sort associative array using custom compare function
    • php get array value with default

    PHP Regex

    • PHP Regex

    PHP Cookbook

    • PHP - assign multi lines string to a variable
    • PHP - call a function with arguments in array examples
    • PHP - get calling file name and line number using debug_backtrace
    • PHP - get class name and file name from an object
    • PHP - get function arguments examples
    • PHP - how to catch errors using set_error_handler
    • PHP - how to initialize static variables
    • PHP - how to use function static variable as cache
    • PHP check if a filename is valid
    • PHP elapsed time
    • PHP execute command and capture shell exit status
    • PHP how to get current url
    • PHP print number to two decimal places
    • PHP remove trailing whitespaces and newline
    • Php equal (==) vs identical (===)
    • Running php eval on code with tags

    PHP functions online

    • PHP functions online
     
    • Home
    • > Tutorials
    • > PHP

    Php equal (==) vs identical (===)

    By admin on Dec 2, 2015

    Equal (==) compares two values after type changing one value to another. Identical compare values and types both and returns true only if they both are same. Some php examples to cover frequently covering cases:

    Compare “0” and 0 using == and ===

    <?php
      var_dump("0" == 0);
      var_dump("0" === 0);
    ?>
    bool(true)
    bool(false)
    
    Env: PHP 7.4.33 (Linux)

    Compare “” and 0 using == and ===

    <?php
      var_dump("" == 0);
      var_dump("" === 0);
    ?>
    bool(true)
    bool(false)
    
    Env: PHP 7.4.33 (Linux)

    Compare “0” and “” using == and ===

    <?php
      var_dump("0" == "");
      var_dump("0" === 0);
    ?>
    bool(false)
    bool(false)
    
    Env: PHP 7.4.33 (Linux)

    Note that “0” and “” do not match even when using ==

    What matches with FALSE using ==

    <?php
      var_dump(FALSE == FALSE);
      var_dump(NULL == FALSE);
      var_dump(0 == FALSE);
      var_dump("0" == FALSE);
      var_dump("" == FALSE);
      var_dump(array() == FALSE);
    ?>
    bool(true)
    bool(true)
    bool(true)
    bool(true)
    bool(true)
    bool(true)
    
    Env: PHP 7.4.33 (Linux)

    What matches with NULL using ==

    <?php
      var_dump(FALSE == NULL);
      var_dump(NULL == NULL);
      var_dump(0 == NULL);
      var_dump("0" == NULL);
      var_dump("" == NULL);
      var_dump(array() == NULL);
    ?>
    bool(true)
    bool(true)
    bool(true)
    bool(false)
    bool(true)
    bool(true)
    
    Env: PHP 7.4.33 (Linux)

    Note that “0” does not match with NULL

    Suggested posts:

    1. Jquery – change table cells color based on value
    2. AngularJS format date using date filter
    3. PHP – split string examples
    4. PHP – empty() vs isset() vs is_null() vs boolean check
    5. WordPress – customize facebook plugin opengraph meta tags
    6. AngularJS ng-href example
    7. Using robotexclusionrulesparser python module to parse robots.txt and crawl a site
    8. PHP – check if a value is in array
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged PHP, PHP cookbook, Tutorials, Web Development
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress