PHP Basic Syntax (ii)

Source: Internet
Author: User
Tags constant definition scalar

" Focus , in which case we would treat other types of values as false for bool values:"
1.0 of the integer type is treated as a pseudo-value of bool, and any non-0 integral type is considered true
2. Floating point 0.0 no matter how many of the following 0 are considered false 0.000000000, the back as long as there is a non-0 value is true
3. The word floating string ' 0 ', as false, all other values are treated as true
4. An empty string is considered a false ' of the bool value, as long as there is a space in the middle is true!
5. NULL as false processing (note)
6. There is nothing in the array, which is an empty array. is treated as a sham. As long as there is a value, this value is considered true even if it is false or Empty.
7. Failed to declare a successful resource

#BOOL Type$bool=true;/*do not add quotation marks*/$bool=false;1. shaping$bool=0; False Non-empty is true2. Boolean type$bool=NULL; False is empty3. Floating-point type$bool= ' 0' false$bool= ' 0.0 ' true/*This special*/4. Character Type$bool= ' '; Fake$bool=""; Fake$bool= "; Really/*Note the space, this special*/        $bool=" "; Really/*Note the space, this special*/5. Empty Array$bool=Array(); Dummy Object$bool=Object(); Fake Resources$bool=Resource(); False

To judge an empty function: (emphasis)
Empty (only One variable), when passed in the variable is 0, false, is null (as long as the false case will return True) (whether Empty)

Isset (variable 1,..., variable n) can pass in one or more variables, so long as one of them becomes null, it returns false (whether Set)

A reference to a variable:

Variable reference question: <?PHP$a=60;$b=&$a;//this really means: to the same place of $ A and $b at the same time, regardless of the value of a or B value, (plainly, is to give $b a nickname, is a value)//its address or point to a;$a=200;$b=300;Echo' $a = '.$a;//The result is $a=200Echo' <br/> ';Echo' $b = '.$b;//The result is $b=200?>

Declaration of a Constant:

1. During operation, the value does not change.
2. Constant value cannot be modified or deleted during operation
3. Constants are global
4. Constants with values, we usually only use scalar
5. Constants can be lowercase, but in order to better differentiate this is a constant, usually uppercase.

Attention:
Call constant, prohibit in enclosed quotation marks, double cited single cited is Not. In this case, read the string

Constant definition:

Define (' constant name ', ' constant value '); Define // Here ABC does not add $, the following constants can be shaped, or floating-point type. 

The rules are as follows:
1. Constant name: Letter (general capitalization), underscore, number (cannot start)
2. Constant value: scalar only.
3. Constants cannot be re-assigned during Operation.
4.unset (ABC); cannot delete//our database address, do not change, we use its characteristics to set a constant
5. Constants are global
6. Constant names are usually capitalized

PHP hyper-global arrays and external variables


Hyper-global arrays:

$_post       Post value $_get       get pass value, can be directly in the browser address bar to pass the value

Attention:

Post sends the content to be received only by post, while the contents of get send can only be received with get
Both the $_request post and the Get mode can be received

Both the $_request Post and the Get mode can be received

Data type:
Sometimes we just need to get the type of data, and then we need to determine the type of the function

Is_float () Type: Judging is not a floating-point type

$b=3.2if(is_float($b)) {echo ' true ';} Else {echo ' false '} // the Result: true

Is_int () type: Determine if the integer type

$a=99; if (is_int($a)) {  echo ' true ';} Else {  echo ' false ';} //the result is: true

Is_bool () Type: Judging is not a Boolean type

$a=false; if (is_bool($a)) {  echo ' true ';} Else {  echo ' false ';} // the Result: true

Is_string () Type: Judging is not a string

$a= ' abc '; if (is_string($a)) {  echo ' true ';} Else {  echo ' false ';} // The result is true

Is_array () Type: Judging is not an array

<? PHP $a=array(1,2,3,4,5,6,); if (is_array($a)) {  echo ' true ';} Else {  echo ' false ';} // The result is true

Is_null () type: Judging is not empty

$a=null; if (is_null($a)) {  echo ' true ';} Else {  echo ' false ';} // the Result: true

Is_object () Type: Judging is not an object

···
Is_numeric () Type: Judging is not a number

···
Is_callable () Type: Judging is not a function

···

Automatic type Conversion:
What Happened:


first, at the time of the operation
Second. At the time of judgment

When the bool value is calculated with the integer phase:
1. Perform a true-to-integer form of a bool value
2. The zero of the bool value is changed to the integral type.

When the bool value is calculated with floating point:
1.bool value will actually become floating point 1.0来 participate in the operation
False of 2.bool value will change to floating point 0.0

When a string is added to an integer or floating point:
1. will kill all the strings that follow
2. Only the preceding values and corresponding integral or floating-point phases are calculated
3. If the string participates in the operation, it must be preceded by a numeric value. If you put it in the middle or back, it will be counted as

PHP Basic Syntax (ii)

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.