1. Tags and annotations
<?php
Code
?>
Use the/* */Comment
2. Output statements
echo "Hello", "World"; echo can output multiple strings, separated by commas
print "Hello"; Print can only output one string
3. Data type
PHP is a weakly typed language
Data types can be converted automatically
4. Variable definition
PHP definition variables start with $
$a = 5;
$b = "Hello";
Variable variable:
* $a = "Hello";
$hello = "World";
echo $ $a; Output World
Determine if the variable is defined:
$a = 3;
echo isset ($a); True returns 1, FALSE returns 0
To clear a variable:
unset ($a);
Determine if the variable is empty:
Empty ($a)
Take address:
$a = 5;
$b =& $a; & Take addresses, A and B take the same address in memory, change one, and the other changes
$b = 10;
echo $a; Output 10
Unset ($b); Simply cancels the value association, the referenced variable does not disappear
echo $a; Output 10
Echo $b;
5. Type conversion
$a = 5;
Var_dump ($a); Output variable Details
$b = (string) $a; Type conversions
Var_dump ($b);
6. Operator expressions
Math operators: +-*/% + +--+ = =
$a = 10;
$b = 3;
echo $a/$b; Output 3.33333333333
String: stitching string with dot not with +
echo "Hello". " World ";
Comparison operator: < > <= >== = = =!
Logical operators: and && or | | !
Error control Operator: @
echo @ $a; Can mask errors
Ternary operator:? :
echo true? " Male ": ' Female ';
PHP Basic Syntax