PHP language basics 02ByACReaper_PHP tutorial

Source: Internet
Author: User
PHP language basics 02 ByACReaper. In fact, writing these php articles is very basic, and many grammar points have been skipped, because the C language and C ++ are better at learning, many of them are similar, but they are written in different places, easy to learn. In fact, writing these php articles is very basic, and many grammar points have been skipped, because the C language and C ++ are better at learning, many of them are similar, I just wrote a different article to facilitate learning. Sharing is also convenient for people to learn in the same situation as me. if I have never learned anything, I don't understand data structures, algorithms, and C, I 'd better not read what I wrote, it is because you should purchase a relatively good reference book for reference.

Definition of constants in 02.1PHP

Define ("CONSTANT_NAME", value [, case_senstivitty]);

"CONSTANt_NAME" is a constant, a string, and value is a value (for any legal php expression, including objects and arrays ). The last one is case-sensitive. The default partition value is true, and the reverse value is false. Constants, like C, are generally written in uppercase.

02.2 operator

Php contains three operators: unary, binary, and ternary. The principle of php type conversion is similar to that of C. The following describes the specific rules for converting php type conversion to memory.

Conversion direction. It cannot be reversed. otherwise, data is lost!

1. type conversion to the largest storage, that is, the largest range.

2. string to integer type conversion, if not enough, to real type conversion.

3. integer to real type conversion

The boolean, Null, and Resource types are similar to integer types. In fact, they are essentially related to integers. As for the reason, you can see the kernel implementation code.

Boolean: False = 0, True = 1

Null = 0;

Resource = The resource's # (id)

02.2.1 binary operators

First, the special binary operators in php are Concatenation Operators (.). Others are the same as those in C.

Secondly, all mathematical operators calculate only numeric operators, and convert other types according to the preceding descriptions.

The following describes the Concatenation Operators (.)

The concatenation operator only concatenates two strings. that is, this operator only processes strings. Therefore, any non-string operands are first converted to strings. This is actually like the heavy-load operator in C ++. you must first specify the type of the heavy-load operator and forcibly convert it.

Eg:

$ Year = 2013;

Print "The year is". $ year;

Then, $ year is converted to The string "2000" internally and then connected to The previous string "The year is.

02.2.2 reference the value assignment operator.

$ Name = "Judy ";

$ Name_alias = & $ name;

$ Name_alias = "Jonathan ";

Print $ name;

Output Jonathan.

From this we can conclude that the so-called reference in php is the same as that in C ++. In fact, its essence is still based on the C pointer. That is, it is equivalent to getting another alias for the variable.

When the function value is returned by reference, a reference symbol is required.

$ Retval = & function_return_by_reference ();

02.3 comparison operator (only speak =, = ,! =)

=

Check whether the two operands are equal !, If type conversion is required, if the rule is 1 = "1", true is returned. if the rule is 1 = 1, true is returned.

===

Equality is similar to =, but the type must be the same. if the type is not automatically converted, the logical value of 1 = "1" is false.

! = And = opposite, and! = The difference is that the type must be the same, and automatic type conversion is not performed.

Bytes. Points...

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.