Home  >  Article  >  Backend Development  >  Introduction to PHP basics_PHP tutorial

Introduction to PHP basics_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:12:49690browse

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, which is generally 4 Bytes, so the range of the integer and the sign bit of the highest digit can be estimated. You can also use the php_int_max constant to view the maximum value of int.

Little knowledge points:

1. When the variable is 0.0 or "0", it means false in the Boolean variable;

2. When the string variable uses double quotes, where Variables and escape characters can be output normally according to their definitions, but when outputting content with single quotes, it will output its content as is, that is, escape characters or variables will not work, but will only output the literal content as is. You can write this yourself Look at the difference in the code. 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 of the division sign "/" can be an integer or a float. It is not just an integer, such as the result of 5/2 is 2.5, whereas in C language the result is 2. When the result cannot be divided, the result displays 14 significant figures.

Operators 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 the "==" 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.

The following example:

$a=2;

$b=2.0;

In the above example, the values ​​of the $a and $b variables are equal Yes, 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.

|| There is a special feature in logical judgment. 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 class. 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 problem:

In Firefox browser, when the form submission method is POST, the corresponding method to obtain the field value is $_POST, not $_REQUEST, while in IE or Firefox , whether it is POST or GET, you can use $_REQUEST to obtain the content. The parameters of $_REQUEST correspond to the name attribute value of the corresponding Input element of the form.



The difference between the break statement in php:

First of all, you must understand what is a loop? 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 levels to jump out of the loop is 1. The

continue statement is used to end this loop, skip the remaining code of this loop and start a new loop.

The goto statement is only valid in php5.3 or above

The role of goto: used to jump out of the 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].

There are two forms of defining a constant:

define("INT_MAX",255) or const INT_MAX=255; The dollar sign cannot be added before the constant, nor can it be reassigned.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313616.htmlTechArticleThe integer in php is signed and cannot represent an unsigned integer. When the integer exceeds the range, it will Automatically convert from integer to float number, you can use the php_int_size constant to view the php integer class...
Statement:
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