string When converting number, intercept the numeric string on the left for conversion, if not then returns 0,
Arrays can directly perform string concatenation operations but cannot perform mathematical operations. It is always true to convert the object type to boolean. The object type cannot be converted to number and string, so string concatenation and mathematical operations cannot be performed. The way to convert a scalar to an array is to set the first element of the array to a scalar and return the array. The scalar is converted to object to get an instance of the stdClass class, and the scalar value is assigned to the property named scalar: Object( [scalar] => 234) Convert array to object to get an instance of stdClass class. The key of the array is the attribute name of the class. Converting object to array is a bit complicated: Methods, static properties, and class constants are discarded Protected attribute names are preceded by a "*" Private properties are preceded by the class name (the case is exactly the same as the class name) For example, an array converted from object is: Array( [*v] => 444 [bf] => 333 [bk] => 99977 [Ak] => 999 [*p] => 888 [a2] => 22) The original objects include: public attribute a2, protected attributes v, p, which class these attributes come from cannot be identified (if overridden, the attributes of the subclass will be taken) Private attributes f and k from class b (from the perspective of the array key, taking bf as an example, it is impossible to determine whether the attribute name is bf or the private attribute f from class b) private property k from class A It is impossible to identify which of b and A is the subclass and which is the parent class (just from the key of the array, it is also impossible to infer which class the original object was constructed from) 5. Logical operations always return true or false (people who write a lot of JavaScript should pay attention). The priority of logical operators from high to low is &&, ||, and, or. The short-circuit effect of logical operators can be used in statements. , but remember that they will not return a value that is not a boolean type like in JavaScript, so be careful when using it in expressions.
6. The comparison of switch is not "===" but "==" (in javascript it is "===") 7. In php4, the comparison method between objects is the same as that of array. In php5, the "==" comparison between object types is true only if they belong to instances of the same class (of course, attributes must also be compared Comparison, this is similar to the "===" comparison of scalars), the "===" comparison between objects is true only if they are the same object. In PHP4, objects that do not include any member variables are judged to be true by empty() String offset offset takes the character's empty() judgment: Take the character corresponding to offset for judgment. Before PHP5.4, when using the index to get characters from the string, the index will be rounded first, so the left side does not contain Numeric strings are converted to 0. After PHP5.4, string indexes in non-integer formats are no longer rounded, so it is judged to be true. Similarly, isset() is judged to be false. For example:
Whether it is "not equal to" or "==", do not use "transitiveness" in cross-type data comparison in PHP: $a == $b; //true $b == $c; //true It does not mean that $a == $c is true Array comparison method
8. Ternary operator?:, unlike most other programming languages, PHP's ternary operator is left associative!
The ternary operation expression is divided into ( $arg == 'B' ) ? 'bus' : ( $arg == 'A' ) ? 'airplane' : ( $arg == 'T' ) ? 'train' : ( $arg == 'C' ) ? 'car' : ( $arg == 'H' ) ? 'horse' : 'feet' ; |