Home >Backend Development >PHP Tutorial >PHP basic syntax and data types study notes_PHP tutorial
An entry-level article on basic PHP syntax and data types. I hope it can provide some help to all PHP beginners.
PHP basic syntax and data types:
(1), PHP basic syntax:
1. Mixed HTML and PHP
3. How to define a variable and how to use it
Four scalar types:
boolean (Boolean type) understood as true or false type
integer (integer type)
Float (floating point type, also called "double") is understood as decimal type
String (string)
array (array)
object
1. Arithmetic operations
2. Assignment operation (such as: $a=100)
3. Comparison operations (such as: $a<$b)
4. Logical operations (such as: $a&&$b)
5. Increment and decrement operations (such as: $a++)
(4) switch conditional statement
switch conditional statement
$i=1;
switch($i){
case 0;
echo "The value of i is 0";
break;
case 1;
echo “The value of i is 1″;
break;
case 2;
echo “The value of i is 2″;
break;
Default: echo "None of the above values";
?>
break n jump out of loop statement
break n jump out of n level loop
Example:
for($i=1;$i<=5;$i++){
echo “
”;
}
?>
//Execute once before judging
do{
echo “Execution loop”;
$a++;
}while($a>100);//Note there is a semicolon
echo “
”;
//Judge first and then execute
while($a>100){
echo “Execution loop”;
$a++;
}
?>
foreach($arr as $key=>$val){}//Traverse the array
count($arr)//length of statistical array
is_array($arr)//Judge array
explode(“key”,$str)//Split the string into an array