So both $myVariable and $anotherVariable end up storing the value 12. This assignment operation also produces a result of 12, which is then assigned to $anotherVariable. In this example, $myVariable is assigned the value 12 (the result of $firstNum + $secondNum). $anotherVariable = $myVariable = $firstNum + $secondNum In the following example, $myVariable takes on the value 12:Īs with most PHP operators, the assignment operator doesn’t just carry out the operation - it also produces a resulting value, which in this case is the value that was assigned. The value to assign doesn’t have to be a literal value - it can be any expression. This is used to assign a value to a variable (as shown in the PHP variables tutorial): The basic assignment operator is = (an equals sign). In this case, 7 divided by 5 is 1 with a remainder of 2, so the result of the modulus operation is 2. % (modulus) is simply the remainder of dividing the two operands. The first four operators should be self-explanatory. PHP features 5 arithmetic operators: Symbol The following sections explore each of these operator types. These can be broken down into the following operator types: Arithmetic Carry out arithmetic operations such as addition and multiplication Assignment Assign values to variables Comparison Compare 2 values Increment/decrement Increase or decrease the value of a variable Logical Perform Boolean logic String Join strings together There are many PHP operators, but this article concentrates on the ones you’re likely to use most often. In this tutorial you look at common PHP operators, and you also explore the concept of operator precedence. The value or values that an operator works on are known as operands. The following PHP code displays the number 5: For example, to add two numbers together to produce a new value, you use the + (addition) operator. PHP operators let you combine values together to produce new values. To manipulate variable values and get useful results, you need to use operators. PHP variables are great for storing values in your script, but they’re not much use on their own.
0 Comments
Leave a Reply. |