PHP Basics: variables, operator summary

Source: Internet
Author: User
Tags null null php basics

PHP type
1. int integer
2. Float type float
3. Strings string
4. Array of arrays
5.NULL NULL
6. Boolean bool false ture
7. Resource Resource
8. Object
Not only the variable name and variable value are stored in the computer, but the type of the variable is stored.
The null type only marks his type as null, his field is empty, NULL is no value.
Variable names in uppercase A-Z lowercase a-Z number 0-9 and _ are case-sensitive and the variable name cannot start with a number

Variable detection isset () detects if a variable declares and sets the declared variable to return TRUE if the undeclared variable returns false but NULL is outside the column null No value also returns false
GetType () detects the type of a variable's type detection variable and another function is the IS_ plus variable type such as Is_array ();
Debug print variable echo is suitable for printing strings and numbers, Print_r suitable for print review and hierarchical data data such as arrays, Object Var_dump is the value and type of the return variable

Type conversion The following values are considered false for the Boolean value: ', 0,0.0.null,false,array. Others will be considered true
Empty () is to detect if a variable is empty if it is not NULL returns FALSE, the value of the previous sentence is also considered null to return True
Assignment and value 1. Value Assignment: 2 people watching two TVs the same station, the value of a changes the value of B does not follow the change of 2. Reference assignment: Two people see the value of the same TV a changes the value of B will also change
Destroying variables some of the larger arrays and objects destroyed can release memory unset () destroys the specified variable note If the value is a reference, destroy one variable and the other variable remains unchanged.
Dynamic variable name dynamic variable name is a representation of PHP flexibility can use the value of the variable to do another variable name such as: $laoda = ' Liubei ';
echo $laoda, ' <br > ';
$paihang = ' Laoda ';
echo $paihang, ' ~ ', $ $paihang;
Ranking
$rank = ' Paihang ';
echo $$ $rank;

Operator three note points in the operator 1. The divisor cannot be zero, the sum of integers in 2.PHP is greater than 4 billion the computer will be saved with a floating-point number, the integer in the computer can not be saved greater than 4 billion, 3. In PHP to get the remainder operation of the film, the result of the positive pair depends on the divisor, the divisor is positive, The divisor is a negative number and the result is a negative number. Dividend is the preceding number.

The result of the comparison operator is a Boolean value. = = and = = = As long as the value is equal = = value equal to the same type
Strpos (), finds the first occurrence of a string that is case-sensitive, if it finds a number that returns the first occurrence of the position, starting with 0, if no return boolean value is found for false


Ternary operator: An expression has a result of 2, if the result is true 1. If the result of false fetch is 2;
Choose:
$a = 5;
$b = 10;
if ($a > $b) {
echo $a greater than $b;
}else{
echo $a less than $b;
// }
Ternary operator: If you want to nest multiple ternary operators to prevent confusion, it is recommended that you wrap them more ().
$a = 5;
$b = 10;
$c = $a > $b? $a greater than $b: $a less than $b;
Echo $c;

logical operators && logic; two conditions for true are satisfied | | Logic or a condition to be satisfied on it;

Increment decrement operator: Try not to recommend it because + +--operation lacks atomicity is one thing to do, but + +--doing two things can create ambiguity under complex statements.
+ +--in the back of the first assignment in the operation such as: $a = 5;  $b = $a + +; echo $a, $b; 6,5;
+ +--in front of the first operation in the assignment such as: $a = 5;  $b =++ $a; echo $a, $b; 6,6;
String operator concatenation operation, can use ', ' and '. ' To splice, the comma is faster than the point, Enho output multiple variables, separated by commas is good, and the point is the first stitching in the output.
Assignment operator, assigning the value to the right of the equal sign to the left of the equals sign.

PHP Basics: variables, operator summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.