Đang chuẩn bị liên kết để tải về tài liệu:
Professional Information Technology-Programming Book part 66
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'professional information technology-programming book part 66', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Summary In this lesson you have learned how to use functions to modularize your code. In the next lesson you will learn about ways to work with numeric data in PHP. Lesson 5. Working with Numbers In this lesson you will learn about some of the numeric manipulations you can perform in PHP. Arithmetic As you would expect PHP includes all the basic arithmetic operators. If you have not used another programming language the symbols used might not all be obvious so we ll quickly run through the basic rules of arithmetic in PHP. Arithmetic Operators Addition is performed with the plus symbol . This example adds 6 and 12 together and displays the result echo 6 12 Subtraction is performed with the minus symbol - which is also used as a hyphen. This example subtracts 5 from 24 echo 24 - 5 The minus symbol can also be used to negate a number for example 20 . Multiplication is performed with the asterisk symbol . This example displays the product of 4 and 9 echo 4 9 Division is performed with the forward slash symbol . This example divides 48 by 12 echo 48 12 Division When you divide two integers the result is an integer if it divides exactly. Otherwise it is a double. A fractional result is not rounded to an integer. Modulus is performed by using the percent symbol . This example displays 3the remainder of 21 divided by 6 echo 21 6 Modulus The modulus operator can be used to test whether a number is odd or even by using number 2. The result will be 0 for all even numbers and 1 for all odd numbers because any odd number divided by 2 has a remainder of 1 . Incrementing and Decrementing In PHP you can increment or decrement a number by using a double plus or double minus -- symbol. The following statements both add one to number number number The operator can be placed on either side of a variable and its position determines at what point the increment takes place. This statement subtracts one from countdown before displaying the result echo -- countdown However the following .