This is a discussion on Operations in PHP within the PHP Programming forums, part of the Web Development category; Comparison operators, as their name implies, allow you to compare two values. If you compare an integer with a string, ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Comparison operators, as their name implies, allow you to compare two values. If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement. PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| Sponsored Links |
| |||
| Here some of comparison operators $a == $b -> Equal $a === $b -> Identical $a != $b ->Not equal $a <> $b -> Not equal $a !== $b ->Not identical $a < $b ->Less than $a > $b ->Greater than $a <= $b ->Less than or equal to $a >= $b ->Greater than or equal to
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Transcription of standard array comparison PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Ternary Operator Another conditional operator is the "?:" (or ternary) operator. PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Ternary operator is a statement, and that it doesn't evaluate to a variable, but to the result of a statement. This is important to know if you want to return a variable by reference. The statement return $var == 42 ? $a : $b; in a return-by-reference function will therefore not work and a warning is issued in later PHP versions.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Error Control Operators PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored. If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable $php_errormsg. This variable will be overwritten on each error, so check early if you want to use it.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include() calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Hi, Binary operators are used on two operands: 2 + 3 14 * 3.1415 $i – 1 These examples are also simple examples of expressions. PHP can only perform binary operations on two operands that have the same type. However, if the two operands have different types, PHP automatically converts one of them to the other’s type, according to the following rules (unless stated differently, such as in the concatenation operator). Attachment 201 Booleans, nulls, and resources behave like integers, and they convert in the following manner:
__________________ Regards, Senraj.A Last edited by senraj : 05-05-2008 at 04:27 AM. |
| |||
| Hi, Numeric Operators All the binary operators (except for the concatenation operator) work only on numeric operands. If one or both of the operands are strings, Booleans, nulls, or resources, they are automatically converted to their numeric equivalents before the calculation is performed (according to the previous table). Numeric Operators.doc
__________________ Regards, Senraj.A |
| |||
| Hi, Concatenation Operator (.) The concatenation operator concatenates two strings. This operator works only on strings; thus, any non-string operand is first converted to one. The following example would print out "The year is 2000": $year = 2000; print "The year is " . $year; The integer $year is internally converted to the string "2000" before it is concatenated with the string’s prefix, "The year is".
__________________ Regards, Senraj.A |
| |||
| Hi, Assignment operators enable you to write a value to a variable. The first operand (the one on the left of the assignment operator or l value) must be a variable. The value of an assignment is the final value assigned to the variable; for example, the expression $var = 5 has the value 5 (and assigns 5 to $var). In addition to the regular assignment operator =, several other assignment operators are composites of an operator followed by an equal sign. These composite operators apply the operator taking the variable on the left as the first operand and the value on the right (the r value) as the second operand, and assign the result of the operation to the variable on the left. For example: $counter += 2; // This is identical to $counter = $counter + 2; $offset *= $counter;// This is identical to $offset = $offset * ➥$counter; The following list show the valid composite assignment operators: +=, -=, *=, /=, %=, ^=, .=, &=, |=, <<=, >>=
__________________ Regards, Senraj.A |
| |||
| Hi, By-Reference Assignment Operator PHP enables you to create variables as aliases for other variables. You can achieve this by using the by-reference assignment operator =&. After a variable aliases another variable, changes to either one of them affects the other. For example: $name = "Judy"; $name_alias =& $name; $name_alias = "Jonathan"; print $name; The result of this example is Jonathan When returning a variable by-reference from a function (covered later in this book), you also need to use the assign by-reference operator to assign the returned variable to a variable: $retval =& func_that_returns_by_reference();
__________________ Regards, Senraj.A |
| |||
| Hi, Comparison operators enable you to determine the relationship between two operands. When both operands are strings, the comparison is performed lexicographically. The comparison results in a Boolean value. For the following comparison operators, automatic type conversions are performed, if necessary. Comparison operators.doc
__________________ Regards, Senraj.A |
| |||
| Hi, Comparison operators For the following two operators, automatic type conversions are not performed and, therefore, both the types and the values are compared. Comparison operators.doc
__________________ Regards, Senraj.A |
| |||
| Hi, Logical operators first convert their operands to boolean values and then perform the respective comparison. Logical Operators.doc
__________________ Regards, Senraj.A |
| |||
| Hi, Short-Circuit Evaluation When evaluating the logical and/or operators,you can often know the result without having to evaluate both operands.For example, when PHP evaluates 0 && 1, it can tell the result will be false by looking only at the left operand, and it won’t continue to evaluate the right one. This might not seem useful right now, but later on, we’ll see how we can use it to execute an operation only if a certain condition is met.
__________________ Regards, Senraj.A |
| |||
| Hi, Bitwise operators perform an operation on the bitwise representation of their arguments. Unless the arguments are strings, they are converted to their corresponding integer representation, and the operation is then performed. In case both arguments are strings, the operation is performed between corresponding character offsets of the two strings (each character is treated as an integer). Bitwise Operators.doc
__________________ Regards, Senraj.A |
| |||
| Hi, Unary Operators Unary operators act on one operand. Negation Operators Negation operators appear before their operand—for example, !$var (! is the operator, $var is the operand). Negation Operators.doc
__________________ Regards, Senraj.A |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| String Operations using different databases | srikumar_l | Database Support | 0 | 12-05-2007 02:27 AM |
| Date Operations in different databases | srikumar_l | |||