PHP, like JavaScript, is also a scripting language.
PHP This is the script that executes on the server, and JavaScript is the script that executes on the client.
<?php//: single-line comment
PHP Code/* Multi-line Comment */
?>
Output string: ①.echo ' Hello World '; echo can output multiple strings at the same time, using "," to connect the output. Example: echo "Hello", "HI";
②.print ' Hello '; Print can only output one string.
Print_r (); Requires an array to output (print) an array.
Var_dump; Output variable content, type, length (typically used for testing purposes)
Data type:
int: integral type
Char: Character (A,b,c) example A or B
String: Strings
BOOL: Boolean type data
DateTime: Date Time
Object: Types of objects
Decmial: Decimal type (large amount of storage can be accurate to how many bits)
Decimal (single-precision floating-point number float, double-precision floating-point number double)
JS and PHP Two languages are weakly typed languages (no data types involved)
Strongly typed languages focus on data types
When defining variables, use VAR (the meaning of mutable variables)
var does not specify a specific data type. Indicates that the data type of the variable can be arbitrarily changed.
If a strongly typed language defines a variable, you need to define the type of the variable
Example: int A (the variable a defined is an integer type)
Define variables:
There are $ before variables
$a = 5;
Var_dump ($a); Output int=5
The type of variable in PHP is changeable at any time, and its data type depends on the value to the right of the equals sign. The variable to the right of an equal sign is an integral type. The right side of the equal sign is a character type, so this variable is character.
Type Conversion Method:
$b = "10";
$b = (int) $b; Parentheses directly to the left of the variable and the data type to be transformed.
Var_dump ($b);
Output is int 10
Type Conversion Mode 2
$b = "10";
Settype ($b, "int");
About variables
unset ($a); Delete a variable
Isset ($a); Determine whether the variable is defined, if the variable A has been defined to show true, no definition of false to determine the existence of a variable, as long as the existence is true, does not exist is false. Is independent of the value of the variable.
Empty ($a); Determine if the value of the variable is empty, if $a=0 the value of variable A is null to display as true if $a= ""; The empty string also represents null (the variable has no value or the value of the variable equals 0 or the variable $a= ""; The variable equals an empty string, or null is the output true, otherwise false)
Fetch Address
$a = 10; $a = 10;
$b =& $a; Output $a= $b =10 $b =& $a; Output $a= $b =5
Echo $b; $b = 5;
echo $a;
Variable variable:
$a = "Hello";
$hello = "Hello"; Output Hello. This mutable variable is only available in PHP, which is wrong in other languages.
echo $ $a;
The definition of a string:
$a = "hel\" Lo "; Output Hel "Lo
$b = ' hel\ ' lo '; Output hel\ "Lo//double quotation mark inside can parse escape character, single quotation mark inside not.
$s = "Zhang San";
$a = "hel\" lo{$s} "; Output Hel "Lo Zhang San//double quotes inside can parse variable, single quote not. To parse the variable $s within a string, you need to add a {} to the variable.
$b = ' hel\ ' lo$s '; Output hel\ "lo$s
Concatenation of strings in PHP ". "No" + "
echo "Hello". "World";
Double quotation marks can parse the escape character (\ "Output"), you can parse the variable "hel{$a}lo" where $a=1 can directly substitute
A special way to define PHP
$a =<<<a
Hello World//Two A to the same line, the last side of the A front can not have anything, no space. And the back one is going to take a line.
A
PHP based on