PHP8 Kinds of variables

Source: Internet
Author: User
Tags arithmetic operators bitwise operators logical operators null null scalar

/*
The data type of the variable 8 kinds
Scalar: boolean bool/INT/floating-point float/string
Composite types: Arrays/Objects Object
Special Type: resource resource/NULL NULL

*/
Var_dump (TRUE);
Var_dump (0);
Var_dump (1.011111);
Var_dump (' I love you ');
Var_dump (Array ());
Var_dump (New Exception ());
Var_dump (mysql_connect (' localhost ', ' root ', ' 123456 '));
Var_dump (NULL);

The data type of the variable
string of strings of characters
Three ways to declare a string:
Double quotes:
1. Double quotes can parse variables
2. Double quotation marks to resolve special characters
such as: \ n (newline) \ t (Horizontal tab TAB)
3. Double quotation marks cannot contain double quotes, and you need to add an escape character if you want to display double quotes.
4. Single and double quotes can be interpolated.

function of judging type
Is_bool ()//Whether it is a Boolean value
Is_int () Is_integer () Is_long ()//is an integral type
Is_float () is_double () is_real ()//is floating point
Is_string ()//Whether it is a string
Is_array ()//Whether it is an array
Is_object ()//Whether it is an object
Is_resource ()//is a resource
Is_null ()//whether it is null
Is_scalar ()//Whether it is a scalar
Is_numeric ()//Whether it is any type of numeric or string number.

Constant fixed amount of constants
Syntax for constants:
Define (' Constant name ', ' constant value ', ' case insensitive ');
The value of the constant, allowing only the assignment to be scalar
Optional Parameter 3:
The default value is false for case-sensitive
True case insensitive
Constant names are generally uppercase
Constants can no longer define or modify values once they are defined
Constant name do not use $
Outputs undefined constants, which output the constant name as a string
I determine if a constant exists
Defined ();
Pre-defined constants in PHP

Define (' Yzl ', ' 3.14 ');
Define (' Yzl ', 3.1415926);
Var_dump (defined (AAA));
Var_dump (AAA);

Echo ' Echo php_version;
Echo ' <br> ';
Echo M_pi;

Magic Constants
Echo ' echo __file__;//the absolute path of the current file
Echo ' <br> ';
Echo __line__;
Echo '


To view all defined constants
Echo ' <pre> ';
Print_r (Get_defined_constants (true));
Echo ' </pre> ';

Operators in PHP
Categorized by operand:
1-dollar operator/2-tuple operator/3-tuple operator
Classification by Function:
Arithmetic operators
String operators
Assignment operators
Comparison operators
logical operators
Bitwise operators
Other operators

+ + self-increment 1 increments
--1 decrease in self-reduction

+ + before the first + + assignment, + + after the first assignment and then + +
--Before the first--and then the value,--After the first assignment and then--

$a = 5;

$b = $a + + + + $a;

$c = + + $a + $b + +;

$d = $a-----$b + $c--;

echo $a. ' <br> ';
echo $b. ' <br> ';
echo $c. ' <br> ';
echo $d. ' <br> ';

/*
Assignment operators
The operand on the left must be a variable
=
When using the compound assignment operator, it is necessary to give the initial value
+ =//$a +=5; Equivalent to $a = $a + 5
-=//$a-=5; Equivalent to $a = $a-5
*=
/=
%=
.=
*/
$a = 10;
$a + = 5;
$a = $a + 5;
echo $a;
Echo '

$str = ";
$str. = ' Me and you '; $str = $str. ' Me and you ';
$str. = ' Heart to heart ';//$str = $str. ' Heart to Heart ';
$str. = ' no base friend ';
$str. = ' Do not program ';

Echo $str;

/*
Comparison operators
When compared, the condition is true to return true, False for false
>
<
>=
<=
= = equals to only judge if the value is equal
= = = All equals both the judging value and the judging type all the same
! = is not equal to only judging if the value is not equal
!== not only judge the value and judge the type of a different, XX

! (= for assignment, = = to determine equality, = = = To determine whether congruent)
*/
$a = 0;
Var_dump (< 0);
Var_dump ($a = = 0);//true
Var_dump ($a = = ' 0 ');//true

Var_dump ($a = = = 0);//true
Var_dump ($a = = = ' 0 ');//false


Var_dump ($a! = 0);//false
Var_dump ($a! = ' 0 ');//false
Var_dump ($a!== ' 0 ');//true
Var_dump ($a!== 0.0);//true

/*
logical operators
To judge whether a thing is true or false returns are true or false bool type

&& and logic and both sides are true, that is true. otherwise false
|| The or logic or both sides are false, that is false. otherwise true
! Not logic does not turn false into true, true change false (take reverse)
Xor different or on both sides is true love, the same is false
*/
&& Logic and
Var_dump (True && true);//true
Var_dump (True && false);//false
Var_dump (False && true);//false
Var_dump (False && false);//false
Echo '

// || Logical OR
Var_dump (True | | false);//true
Var_dump (True | | true);//true
Var_dump (False | | true);//true
Var_dump (False | | false);//false
Echo '

// ! Logical Non-
Var_dump (!true);//false
Var_dump (!false);//true
Echo '


&& | | Short Circuit problem
$a = 1;
if ($a = = 2 && $b = 100) {
$b is not assigned worth the left value is false, then it will not be executed directly return false
Echo ' true interval ';
}else{
echo ' false interval ';
}
Echo $b;
Echo '

$c = 1;
if ($c = = 1 | | $d =200) {
Echo ' true interval ';
}
Echo $d;
Echo '

Small short-circuit applications
$e = ' 555 ';
Is_int ($e) && $e +=10;
Echo $e;

/*
Other operators
?: Ternary operator

' Execute operator
@ ERROR Control character
*/

if (10>0) {
Echo ' 11111 ';
}else{
Echo ' 22222 ';
// }
Echo (< 0)? ' 11111 ': ' 22222 ';
Echo '
$name = Empty ($_get[' a '])? ' User not filled in name ': $_get[' a '];

Echo $name;

PHP8 Kinds of variables

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.