PHP Tutorial

Php advanced, mysql database, php examples, php reference, php operators.

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Conditional assignment operators

PHP Arithmetic Operators

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

PHP Assignment Operators

The PHP assignment operators are used with numeric values to write a value to a variable.

The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

Advertisement

PHP Comparison Operators

The PHP comparison operators are used to compare two values (number or string):

PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable's value.

The PHP decrement operators are used to decrement a variable's value.

PHP Logical Operators

The PHP logical operators are used to combine conditional statements.

PHP String Operators

PHP has two operators that are specially designed for strings.

PHP Array Operators

The PHP array operators are used to compare arrays.

PHP Conditional Assignment Operators

The PHP conditional assignment operators are used to set a value depending on conditions:

PHP Exercises

Test yourself with exercises.

Multiply 10 with 5 , and output the result.

Create your site with Spaces

COLOR PICKER

colorpicker

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

[email protected]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials

Top references, top examples, get certified.

  • Language Reference

Logical Operators

The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See Operator Precedence .)

Example #1 Logical operators illustrated

The above example will output something similar to:

User Contributed Notes 21 notes

To Top

  • Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

If condition not working on operator 'equal' and working on assignment operator

Hello I have a strange problem in which my If statement is not working. I am doing a simple user registration and would like to check if the variable 'sendmail' is equal to 1, to send an e-mail if not to not send e-mail. I have shorten the mail function code for better understanding:

So the problem is that the condition in this case if ($POST['sendmail'] == 1) is not working, and it is not sending the e-mail. In case if I write it like this if ($POST['sendmail'] = 1) this way is working no matter what argument the variable sendmail have inside it, it is always sending the e-mail.

this is from where sendmail is coming

I've checked the post array and the variable sendmail is inside so this can't be the problem. Any help will be very welcome. Thank you.

John Siniger's user avatar

  • $POST['sendmail'] should be $_POST['sendmail'] . –  gen_Eric Apr 16, 2014 at 16:12
  • 2 What @RocketHazmat said. Enable error reporting to discover such errors easily. –  Amal Murali Apr 16, 2014 at 16:13
  • @AmalMurali Excellent point! (: –  Skewled Apr 16, 2014 at 16:14

2 Answers 2

Doing assignment instead of comparison is not what you want.

is truthy because the value being assigned ( 1 ) is truthy. If you did if ($var = 0) instead it would never pass.

You should also consider using === . This works if you know the type of both variables. $_POST input is always strings, so:

Halcyon's user avatar

  • " Doing assignment instead of comparison is not what you want. " — Where in this code does he assign a value? –  Amal Murali Apr 16, 2014 at 16:13
  • Read his original question. He mentions changing the comparison for assignment. –  Halcyon Apr 16, 2014 at 16:14
  • okay I fixed the $_POST, if I use == it is sending every time the e-mails no mater what is choosen if I use === it is not sending anything never. –  John Siniger Apr 16, 2014 at 16:24
  • That makes no sense. Is the value of $_POST["sendmail"] "1" , "0" or something else? –  Halcyon Apr 16, 2014 at 16:27
  • this is the problem, this is the result of the post array in case If I choose no: ["sendmail"]=> string(1) "0" –  John Siniger Apr 16, 2014 at 16:29

Skewled's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .

Not the answer you're looking for? Browse other questions tagged php or ask your own question .

  • The Overflow Blog
  • What it’s like being a professional workplace bestie (Ep. 603)
  • Journey to the cloud part I: Migrating Stack Overflow Teams to Azure
  • Featured on Meta
  • Moderation strike: Results of negotiations
  • Our Design Vision for Stack Overflow and the Stack Exchange network
  • Temporary policy: Generative AI (e.g., ChatGPT) is banned
  • Discussions experiment launching on NLP Collective
  • Call for volunteer reviewers for an updated search experience: OverflowAI Search

Hot Network Questions

  • Damaged spokes behind the cassette
  • Can you steal a complete color set from a player that uses a wild card with the deal breaker action card? - Monopoly Deal
  • Can a 650 nm 250 mW diode laser remove the first layer of a PCB?
  • Getting child to eat (preschooler)
  • Has Arnold Schwarzenegger's accent ever been acknowledged in-universe in a movie?
  • Prefix code generator
  • Why do the Nordics have a low birth rate despite their government providing all parents with free childcare and parental leave?
  • Feasibility of “invisible” orbital bombs
  • Why are Hollywood studios permitted to collectively bargain with employees, and what are the limits of this apparent antitrust exemption?
  • Why are my newlines turned into \Omega?
  • Did "Joe the Plumber" perform plumbing work for money between when he left the Air Force and October 2008?
  • The role of the Elements in the development of mathematics
  • How to slow down while maintaining altitude
  • Meaning of "How you get any work done is beyond me"
  • Stretching left, "inside" and right delimiters
  • Drawing a maths protractor
  • Word for when a life event (like a vacation) is coming to an end and you feel an immense feeling of sadness due to not wanting to leave
  • Did Einstein say "Do not worry about your difficulties in mathematics, I assure you that mine are greater"?
  • Why did 1990s-2000s LCD all use 60 Hz refresh?
  • What does the clown mean by saying that brothels in the cities "shall stand for seed" in the second scene of "Measure for Measure"?
  • Why do people say 'topless' but not 'topful'?
  • What do Americans say instead of “can’t be bothered”?
  • How much monthly costs can I expect if I get a kitten or two?
  • Prism: full spectrum including UV + IR

php assignment not equal

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Code Translation Project

Don't lose in a world of programming languages

PHP - Not equal to: !=

Description.

  • par1 - Any number
  • par2 - Any number
  • Result - Logical value Returns a true, if the first number is Not equal to the second, otherwise false.
  • Loose and Strict Equality Checks in PHP

the Loose Equality Check in PHP

The loose not equal check in php, the strict equality check in php, the strict not equal check in php.

Loose and Strict Equality Checks in PHP

This article will explain how to perform loose and strict equality checks in PHP.

Please enable JavaScript

For the loose equality checks, you’ll use some built-in check operators like the equality operator == and the not equal operator != .

Also, for the strict equality checks, you’ll use the strict versions of these operators.

The loose equality check in PHP uses the double equality sign == and not the equal sign != sign. Both operators are considered loose.

That is because they do not consider the data type of the compare variables. As a result, one in integer form will equal one in a string format.

We have three checks all will return true. The first check compares zero in string format and as a number. With the equality operator, PHP will return true.

The equality operator considers the values and not the data type. False and zero will return true for the second equality check because false means zero in computing terms.

But here, if you need to consider the data types of false and zero, an equality check will not suffice.

The final check between NULL and false should return false since NULL means an absence of value.

While false means the value is there, it’s empty or zero-value. But, the equality check returns true.

Like loose equality check, loose not equal check does not consider the data type during comparison. As a result, you can get unexpected results.

Our next code example is based on the previous code example. But, here, we use the loose, not equal check to perform the comparison.

All checks will return false. This is because the loose, not equal operator considers the value and not the data types of the variables.

The following outputs are from the else block of each comparison:

As the name implies, the strict equality check is strict during comparisons. This means strict equality checks that the variables are equal in value and data types.

One string format will never equal one in number with a strict equality check. Also, Boolean false will not equal zero.

All checks will return the appropriate information about the variables during our next code block comparisons.

The strict, not equal check will return the correct results when the comparison data and variables are not equal .

When you run the next code block, you get the correct results about the comparisons.

Habdul Hazeez avatar

Habdul Hazeez is a technical writer with amazing research skills. He can connect the dots, and make sense of data that are scattered across different media.

Related Article - PHP Operator

  • PHP Spaceship Operator
  • PHP Spread Operator
  • Null Coalescing vs Elvis Operator in PHP
  • Assignment by Reference Operator in PHP
  • Question Mark Symbol in PHP

PHP Comparison Operators

Php tutorial index.

Use of PHP Comparison Operators is comparing two values (number or string).

Home » PHP Tutorial » PHP Comparison Operators

PHP Comparison Operators

Summary : in this tutorial, you will learn how to use PHP comparison operators to compare two values.

Introduction to PHP comparison operators

A comparison operator allows you to compare two values and returns true if the comparison is truthful and false otherwise.

The following table illustrates the comparison operators in PHP:

Equality Operator (==)

The equality returns true if both values are equal; otherwise, it returns false . The following example returns true because 10 is equal 10:

The following example returns false because 10 is not equal 20 :

The following example compares the number 20 with a string '20' , it also returns true .

If you want to compare two values with the consideration of type, you can use the identical operator ( === ).

Not equal to operator (!=, <>)

The not equal to (!=, <>) operator returns true if the lefthand value is not equal to the righthand value; otherwise, it returns false . For example:

Identical operator (===)

The identical operator returns true if both values are equal and have the same type; otherwise returns false .

The following example uses the identical operator to compare a string and a number. It returns false because these values have different types:

Not identical operator (!==)

The not identical operator (!==) returns true if the values are not equal or they do not have the same type; otherwise, it return false . For example:

Greater than (>)

The greater than return true if the lefthand value is greater than the righthand value; otherwise, it returns false :

Greater than or equal to (>=)

The greater than or equal to operator returns true if the lefthand value is greater than or equal to the righthand value; otherwise, it returns false. For example:

Less than (<)

The less than operator returns true if the lefthand value is less than the righthand value; otherwise, it returns false. For example:

Less than or equal to (<=)

If the lefthand value is less than or equal to the righthand value, the less than or equal to operator returns true; otherwise, it returns false. For example:

In this tutorial, you have learned how to use the PHP comparison operators to compare two values of the same or different types.

IMAGES

  1. PHP Assignment For Students

    php assignment not equal

  2. PHP Assignment Help

    php assignment not equal

  3. PHP Assignment Help can assist you to get better scores

    php assignment not equal

  4. PHP Assignment Help and Writing Service by Programing Expert

    php assignment not equal

  5. Php Programming Assignment Help & Php Programming Project and Homework Help

    php assignment not equal

  6. PHP programming beginner

    php assignment not equal

VIDEO

  1. PHP : Conditions

  2. Understanding PHP Data Types

  3. A brief summary of PHP

  4. 1

  5. php://input

  6. #09

COMMENTS

  1. PHP: Assignment Operators

    Assignment Operators. The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the right (that is, "gets set to"). The value of an assignment expression is the value assigned.

  2. operators

    4 Answers Sorted by: 169 == and != do not take into account the data type of the variables you compare. So these would all return true: '0' == 0 false == 0 NULL == false === and !== do take into account the data type. That means comparing a string to a boolean will never be true because they're of different types for example.

  3. PHP Operators

    The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right. PHP Comparison Operators The PHP comparison operators are used to compare two values (number or string): PHP Increment / Decrement Operators

  4. Reference assignment operator in PHP, =&

    5 Answers Sorted by: 148 It's not deprecated and is unlikely to be. It's the standard way to, for example, make part of one array or object mirror changes made to another, instead of copying the existing data.

  5. PHP: Comparison Operators

    If both operands are numeric strings, or one operand is a number and the other one is a numeric string, then the comparison is done numerically.These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.

  6. php

    You are asking if the value of a string is not A or Not B. If it is A, it is definitely not also B and if it is B it is definitely not A. And if it is C or literally anything else, it is also not A and not B. So that statement always (not taking into account schrödingers law here) returns true.

  7. php is not equal to and is not equal,equal to

    2. PHP allows values to be freely converted from one type to another. If you convert a string "456" to a number, it will be converted to 456. Very convenient. The PHP comparison operator == only checks value. So, "456"==456. Now, "" (empty string) would be equal to 0, and to FALSE, and to NULL.

  8. PHP: Operators

    Operator are used to perform operation. Operator are mainly divided by three groups. 1.Uniary Operators that takes one values. 2.Binary Operators that takes two values. 3.ternary operators that takes three values. Operator are mainly divided by three groups that are totally seventeen types. 1.Arithmetic Operator.

  9. PHP if not equal(!=) and or (||) issue. Why doesnt this work?

    Part of PHP Collective 5 I know this is simple PHP logic but it just won't work... $str = "dan"; if ( ($str != "joe") || ($str != "danielle") || ($str != "heather") || ($str != "laurie") || ($str != "dan")) { echo "<a href='/about/".$str.".php'>Get to know ".get_the_author_meta ('first_name')." →</a>"; } What am I doing wrong? php Share

  10. PHP: Logical Operators

    In addition to what Lawrence said about assigning a default value, one can now use the Null Coalescing Operator (PHP 7). Hence when we want to assign a default value we can write:

  11. How do the PHP equality (== double equals) and identity (=== triple

    Difference between == (equal) and === (identical equal) PHP provides two comparison operators to check equality of two values. The main difference between of these two is that '==' checks if the values of the two operands are equal or not. On the other hand, '===' checks the values as well as the type of operands are equal or not. == (Equal)

  12. php

    Hello I have a strange problem in which my If statement is not working. I am doing a simple user registration and would like to check if the variable 'sendmail' is equal to 1, to send an e-mail if not to not send e-mail. I have shorten the mail function code for better understanding:

  13. PHP

    Not equal to in PHP programming language is used as follows: !=. Short description of Not equal to. Shown on simple examples. ... Assignment. Assignment. Statements. Expression statement Block statement. Loops. Loop with condition at the end Loop with condition on the beginning. Conditional statements.

  14. php tutorials: not equal to

    PHP Not Equal To . In the previous section, you saw what Comparison Operators were.In this lessons, we'll explore the Comparison Operator for Not Equal To: !=. So open up your text editor, and add the following script:

  15. How To Write Conditional Statements in PHP

    To continue practicing conditional statements: Try using different operators: <, >, ==, ===. Combine operators with and or or. Recreate an if statement using a ternary, null coalescing, or spaceship operator. For more information on how to code in PHP, check out other tutorials in the How To Code in PHP series.

  16. Loose and Strict Equality Checks in PHP

    the Strict Not Equal Check in PHP This article will explain how to perform loose and strict equality checks in PHP. Introducción a la termodinámica - Leyes y conceptos básicos For the loose equality checks, you'll use some built-in check operators like the equality operator == and the not equal operator !=.

  17. PHP not equal

    One of the comparison operators in PHP is not equal, which is represented by the symbol != or <>. Whenever we want to compare the data types of the two given values regardless of whether the two values are equal or not, we make use of not equal operator in PHP.

  18. PHP Comparison Operators

    Use of PHP Comparison Operators is comparing two values (number or string). Example: <?php $a = 20; $b = 30; if( $a == $b ) { echo "a and b is equal"; }else { echo "a is not equal to b"; } ?> Share this page!

  19. PHP Comparison Operators

    Operator Name Description Equal to Return trueif both operands are equal; otherwise, it returns false. Not equal to Return trueif both operands are equal; otherwise, it returns false. Identical to Return trueif both operands have the same data type and equal; otherwise, it returns false. Not identical to

  20. PHP Operators

    Published Feb 27, 2022 PHP We will go into the various operators that you can use within the PHP language within this guide. An operator in PHP is used to perform operations on variables. For example, PHP can use operators to take one or more values and create a new resulting value.