Home  >  Article  >  Backend Development  >  PHP Language Basics 02 By ACReaper_PHP Tutorial

PHP Language Basics 02 By ACReaper_PHP Tutorial

WBOY
WBOYOriginal
2016-07-14 10:12:15750browse

In fact, writing these PHP articles is very basic, and many grammatical points have been skipped, because C language and C++ are relatively easy to learn, and they are very similar, but they are written in different places to facilitate learning. Sharing it will also make it easier for people in the same situation as me to learn. If you have never learned anything, do not understand data structures, algorithms, or C, it is best not to read what I wrote, but to buy a comparison book. Good reference books to refer to.

02.1 Definition of constants in PHP
define("CONSTANT_NAME",value[,case_senstivitty]);
Where "CONSTANt_NAME" is a constant, a string, and value is the value (any legal php expression, including objects and arrays). The last one can be known from the literal meaning that it means case-sensitive. The default value is true, otherwise it is false. Constants are the same as C and are generally written in uppercase letters.
02.2 Operator
php contains three operators, unary, binary and ternary operators. The principle of PHP type conversion is similar to that of C. It converts in the direction of saving more. The following are the specific rules.
Change direction. Cannot reverse, otherwise the data will be lost!
1. Convert to the most stored type, which means the largest range.
2. Convert the string to integer type, if not enough, convert it to real type.
3. Conversion from integer type to real type
The boolean type, Null type, and Resource type are also similar to integer types. In fact, it can be understood that their essence is related to integers. As for the reason, you can know the reason by looking at the kernel implementation code.
Boolean: False = 0, True = 1
Null = 0;
Resource = The resource’s #(id)
02.2.1 Let’s talk about binary operators
First of all, the special binary operator in PHP is the concatenation operator (.). The others are the same as in C language.
Secondly, all mathematical operators only calculate numeric operators. When encountering other types, follow the conversion mentioned above.
The following focuses on the concatenation operator (.)
The concatenation operator only concatenates two strings, that is, this operator only processes strings, so any non-string operands will be converted into strings first. This is actually like the overloaded operator in C++. You must first specify the type that the overloaded operator operates on and cast it.
eg:
$year = 2013;
print "The year is" . $year;
will internally convert $year into the string "2000" and then concatenate it with the previous string "The year is".
02.2.2 Reference assignment operator.
$name = "Judy";
$name_alias = & $name;
$name_alias = "Jonathan";
print $name;
then output Jonathan.
From this we can conclude that the so-called references in PHP are the same as those in C++. In fact, their essence is still based on C pointers. That is equivalent to giving the variable another alias.
When returning the value of a function by reference, reference symbols must be used.
$retval = & function_return_by_reference();
02.3 Comparison operators (only ==, ===, !==)
==
Check if two operands are equal! , if type conversion is required, the rule is that 1 == "1" returns true, and 1 == 1 also returns true.
===
Congruence is similar to ==, but the types must be the same. Automatic type conversion is not performed, so 1 === "1" logical value is false
!== is the opposite of ===. The difference from != is that the types must be the same and automatic type conversion is not performed.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477214.htmlTechArticleIn fact, writing these PHP articles is very basic, and it skips many grammatical points, because C language and C++ I learned it relatively well. They are very similar, but the differences are written down to make it easier to learn. Points...
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