Basic PHP Learning
<?php
Type
$test = 123;
Var_dump ($test);//print out type and value
Echo '
echo GetType ($test);//get variable type-"integral type"
Echo '
$res = (bool) $test;//temporary conversion type
Var_dump ($res);//true
Var_dump ($test);//123
Echo '
Settype ($test, ' string ');//change type
Var_dump ($test);//"123"
Echo '
Assign value
Var_dump (
0== $sdfg//null-->0 1+NULL;//1
);
$i = 5;
$i + +;
Echo $I;//6
Echo '
Character connections
$str 1= "Hello";
$str 2. = $str 1; $str 2=null. $str 1;
$str 2. = '! '; $str 2= $str 2. '! ';
Echo $str 2; Hello!
logical operators and && and; or;! Non -
$i = 1;
$j = 0;
Var_dump (
$i && $j//false
$i--&& $--j//true
);
?>
@ Error Suppression symbol, suppressing error output
$var = 1;
@settype ($var, ' King ');
echo @ (4/0);
Die exit: Terminate program execution
Output 99 multiplication table
For ($i =1; $i <=9; $i + +) {
For ($j =1; $j <=9; $j + +) {
Echo "{$i}x{$j}=". ($i * $j). ' ";
}
Echo ' <br/> ';
}
Output a table
The difference between the while and do while
Arrays in PHP
Declaring an array: array ()//[]
Use Principle: find the building value based on the name of the building
Defining an indexed array
$arr = [23,54, ' King ', true];
Print_r ($arr);//print Array
$arr = [
23=> ' a ',
54=> ' B ',
-12=> ' C ',
23=> ' d '
];
Print_r ($arr);
Duplicate name will produce overwrite
Iterate through the array method in Php:
foreach ($arr as $k = = $v) {
Echo $k, $v;
}
Basic PHP Learning