Home > Backend Development > PHP Tutorial > Overview of PHP basics_PHP tutorial

Overview of PHP basics_PHP tutorial

WBOY
Release: 2016-07-13 17:19:24
Original
736 people have browsed it

php basic knowledge

Integer numbers in PHP are signed and cannot represent unsigned integers. When the integer number exceeds the range, it will be automatically converted from an integer number to a float number. You can use the php_int_size constant to view the bytes occupied by the PHP integer type. It is generally 4 bytes, so the range of the integer and the highest digit sign bit can be estimated. You can also use the php_int_max constant to view the maximum value of int.
Tips of knowledge:
1. When the variable is 0.0 or "0", it means false in the Boolean variable;
2. When using double quotes for a string variable, the variables and escape characters can be output normally according to their definitions, but when using single quotes to output the content, it will output its content as is, that is, the escape characters or variables will not work. Only the literal content will be output as is. You can write the code yourself to see the difference. Personally, I feel that the definition of PHP variables is a bit similar to JS, because you don't need to specify any type at all, and its type completely depends on the actual type you use.
3. PHP arithmetic operators:
Note: The result obtained by the division sign "/" can be an integer or a float. It is not just an integer. For example, the result of 5/2 is 2.5, but in C language the result is 2. When the result cannot be divided, the result displays 14 significant figures.
There are five operators + , - , * , / , and % .
The symbol that connects two strings is not the + sign in Java, but the . dot sign. The dot sign will automatically treat the preceding and following variables as strings.
The difference between “==” symbol and “===”:
The "==" symbol means that it is true only if the values ​​on the left and right are equal.
The "===" symbol means that not only the values ​​on the left and the right are equal, but also the variable types should be equal before true is returned.
Example below:
$a=2;
$b=2.0;
In the above example, the values ​​of the $a and $b variables are equal, but the types are not equal! Everything using == is true and === is false.
$a !== $b means that the result is true as long as the values ​​​​of a and b are not equal or the types are not equal.
$a != $b means the result is true only when the values ​​of a and b are not equal.
$a <> $b means the same as $a != $b.
echo $a==$b The output content is not true or false. But 0 and 1, 1 represents true and 0 represents false.
There are also >= and <= symbols indicating greater than or equal to, less than or equal to respectively.
|| Logical judgment has a special feature. When the previous judgment is true, the expression after the "||" symbol will not be executed. Be careful about this! The same goes for the && symbol. This phenomenon is called a short circuit. Short circuit and and short circuit or are the representatives. The || symbol can be replaced by or. Similarly, the && symbol can be replaced by and. But there are still some differences between or and and in English: the or operator is lower than =. For example
$a = false || true; //a returns true;
$a = false or true; //=》 ($a = false ) or true;
var-dump($a,$b);
Similarly, the and symbol has a similar situation.
Type operator: instanceof, used to determine whether the data is an instance of a certain type. This is similar to java. The result returns true or false.
++ and - operators only apply to variables, not constants!
The switch statement in php can be of Boolean type within the brackets! The string "0" is treated as false. The default statement can be placed anywhere without affecting the execution order of other case statements! Even if it is placed in the first sentence of the switch statement. But be careful to remember to write the break statement.
Form submission issues:
In Firefox, when the form submission method is POST, the corresponding method to obtain the field value is $_POST, not $_REQUEST. In IE or Firefox, you can use $_REQUEST whether it is POST or GET. to get the content. The parameters of $_REQUEST correspond to the name attribute value of the corresponding Input element of the form.
Differences in the break statement in php:
First of all, you must understand what is a cycle? A loop is a loop consisting of the curly braces of the for and while keywords. This is different from the curly braces of the if statement. The continue statement is generally placed in the if statement, and is generally used to skip the current loop of the for loop or This iteration of the while loop. Never think that the curly braces in the for loop represent a loop, and the curly braces under the if statement are not a loop.
The break statement can be followed by a number to indicate which level of loop to jump out of. The brace area where the break statement is located is the first level of loop. Increasingly from the outside in, rather than from the outside in. But note that the number is so large that it exceeds the outermost loop! For example, there are only 3 levels of loops in total, but you have to jump 4 levels, which will make an error! The default number of break loop levels is 1.
The
continue statement is used to end this loop and skip the remaining code of this loop to start a new loop.
The goto statement is only valid in php5.3 or above version
The role of goto: used to jump out of a loop to replace the break statement of multiple loops. Make your code cleaner!
The difference between variables and constants in php:
1. There is no dollar sign in front of the constant.
2. Constants are defined through the define() function or const and cannot serve as lvalues ​​in assignment statements.
3. Constants can be used and accessed anywhere regardless of the scope of the variable.
4. Once a constant is defined, it cannot be redefined or undefined.
5. The value of a constant is a scalar [basic data type float, int, string, boolean].
Define two forms of a constant:
define("INT_MAX",255) or const INT_MAX=255; cannot add a dollar sign before the constant, nor can it be reassigned.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532690.htmlTechArticlephp basic knowledge The integer in php is signed and cannot represent an unsigned integer. When the integer exceeds the range When, it will be automatically converted from an integer number to a float number. You can use the php_int_size constant...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template