tailieunhanh - Phát triển web với PHP và MySQL - p 7

PHP Crash Course CHAPTER 1 35 TABLE Continued 1 PHP CRASH COURSE Associativity left left right left left left left left left left n/a n/a left left left right right n/a n/a Operators xor and print = += -= *= /= .= %= &= |= ^= ~= = ? : || && | ^ & == != === = + - . * / % ! ~ ++ -- (int) (double) (string) (array) (object) @ [] new () Notice that the highest precedence operator is one we haven’t covered yet: plain old parentheses. The effect of these is to raise the precedence of whatever is contained. | PHP Crash Course Chapter 1 35 1 Table Continued Associativity Operators left xor left and right print left . . - _ left left left left left left n a i n a left left - . left right I _ -- int double string array object @ right n a new n a PHP Crash Course Notice that the highest precedence operator is one we haven t covered yet plain old parentheses. The effect of these is to raise the precedence of whatever is contained within them. This is how we can work around the precedence rules when we need to. Remember this part of the last example totalamount totalamount 1 taxrate If we had written totalamount totalamount 1 taxrate the multiplication operator having higher precedence than the addition operator would be performed first giving us an incorrect result. By using the parentheses we can force the subexpression 1 taxrate to be evaluated first. 36 Using PHP Part I You can use as many sets of parentheses as you like in an expression. The innermost set of parentheses will be evaluated first. Variable Functions Before we leave the world of variables and operators we ll take a look at PHP s variable functions. These are a library of functions that enable us to manipulate and test variables in different ways. Testing and Setting Variable Types Most of these functions have to do with testing the type of a function. The two most general are gettype and settype . These have the following function prototypes that is this is what arguments expect and what they return. string gettype mixed var int settype string var string type To use gettype we pass it a variable. It will determine the type and return a string containing the type name or unknown type if it is not one of the standard types that is integer double string array or object. To use settype we pass it a variable that we would like to change the type of and a string containing the new type for that variable from the previous list. We can use these as follows a 56 echo gettype a . br settype a double echo gettype a

TỪ KHÓA LIÊN QUAN