PHP Developer’s Dictionary IT-SC book 85 variable = string variable1 = variable2 variable1 = &variable2 Description The = operator will assign variable to the num or string on the right side of the operand. The second syntactical definition shows how a variable can be assigned the same value as another variable—a "copy" is made. The final definition shows the assignment of variable2 to variable1 as a reference, which means that if variable2 changes, so does variable1 . $first = 5; $second = $first; // $second = 5 now += Syntax num1 += num2 Description The += operator is used when you want to add num1 to num2 and assign the new value to num1 . These values are numerical. $num = 5; $num += 3; // $num now equals 8 -= Syntax num1 -= num2 Description PHP Developer’s Dictionary IT-SC book 86 The -= operator is used when you want to subtract num2 from num1 and assign the new value to num1 . These values are numerical. *= Syntax num1 *= num2 Description The *= operator is used when you want to multiply num1 by num2 and assign the new value to num1 . These values are numerical. $num = 5; $num *= 3; // $num now equals 15 /= Syntax num1 /=num2 Description The /= operator is used when you want to divide num1 by num2 and assign the new value to num1 . These values are numerical. %= Syntax num1 %=num2 Description The %= operator is used to obtain the integer remainder of dividing num1 by num2 and assign the new value to num1 . For instance, if num1 =5 and num2 =3 , the integer returned from this operation will be 2 and it would be stored in num1 . These values are numerical. PHP Developer’s Dictionary IT-SC book 87 Bitwise Bitwise operators are one of the most difficult operations to understand for new programmers. In short, they convert the items into their binary equivalents, such as and and or , for operations that they are to perform. Note Going into detail on the overall concept of bitwise operations is beyond this scope of this book, but the descriptions and examples contained in this section should provide enough information to enable you to perform any bitwise tasks you need. & (and) Syntax variable1 & variable2 Description The & operator, after the conversion of variable1 and variable2 to their binary equivalents, will check to see where bit instances are both equal to 1. To help you understand this, let's take a look, in Table 4.2 , at the binary representation of 5 and 6 and see how applying the & operator effects the result. Table 4.2. Example of Using the & Operator Number Binary Equivalent 5 101 6 110 Result 100 = 4 As you can see in the table, the result is true only when both binary positions are 1. | (or) Syntax variable1 | variable2 Description PHP Developer’s Dictionary IT-SC book 88 The | operator, after the conversion of variable1 and variable2 to their binary equivalents, will check to see where either bit instances are equal to 1. To help you understand this, let's take a look, in Table 4.3 , at the binary representation of 5 and 6 and see how applying the | operator effects the result. Table 4.3. Example of Using the | Operator Number Binary Equivalent 5 101 6 110 Result 111 = 7 As you can see in the table, the result is true when either binary position is 1. ^ (xor) Syntax variable1 ^ variable2 Description The ^ operator, after the conversion of variable1 and variable2 to their binary equivalents, will check to see where either bit instances, but not both, is equal to 1. To help you understand this, let's take a look, in Table 4.4 , at the binary representation of 5 and 6 and see how applying the ^ operator effects the result. Table 4.4. Example of Using the ^ Operator Number Binary Equivalent 5 101 6 110 Result 011 = 3 As you can see in the table, the result is true only when either binary position is 1 and not both. ~ (not) Syntax ~variable Description The ~ operator, after the conversion of variable to its binary equivalent, will reverse the bit instances. For instance, if you had the number 4 in binary (100) and you applied the ~ operator, the new value would be 2 (011). PHP Developer’s Dictionary IT-SC book 89 << (Shift Left) Syntax variable1 << variable2 Description The << operator will shift variable1 by variable2 bits to the left. This means that the right side of the binary version of variable1 will become "padded" with variable2 number of zeros. This is often used to multiply by two for each variable2 (that is, if variable2=2, it will multiply by 4). >> (Shift Right) Syntax variable1 >> variable2 Description The >> operator will shift variable1 by variable2 bits to the right. This means that the left side of the binary version of variable1 will become "padded" with variable2 number of zeros. This is often used to divide by two for each variable2 (that is, if variable2 =2 , it will divide by 4). Comparison The lists of comparison operators are most often used in conjunction with the control structures. Within the control structure, programmers use comparison operators to compare variables, strings, numeric values, and so on to check whether the body of the control structure should be performed. For example, you might want to know whether a variable was greater than 10 before performing, and it is the comparison operators that enable you to do this. == (Equal) Syntax variable1 == variable2 Description . PHP Developer’s Dictionary IT-SC book 85 variable = string variable1 = variable2 variable1. $num = 5; $num += 3; // $num now equals 8 -= Syntax num1 -= num2 Description PHP Developer’s Dictionary IT-SC book 86 The -= operator is used when you want to subtract num2. from this operation will be 2 and it would be stored in num1 . These values are numerical. PHP Developer’s Dictionary IT-SC book 87 Bitwise Bitwise operators are one of the most difficult