I spent an hour reviewing PHP, which I haven’t touched in many years, and marked it. I learned it in my sophomore year of high school.
1. The code is embedded in
2. Output function echo, equivalent to document.write in js
3. You can use single quotes when printing double quotes or use single quotes when printing double quotes.
echo 'She said,"how you are?"';
echo "she said,'how you are?'";
4. You can use the same quotation marks or print symbols that need to be escaped, echo 'I 'm just ducky.'; echo "she said, "How are you?"";
5. It is recommended to use shell style for comments, #this is a comment
6. The variable is the same as c, preceded by $.
echo $money;
echo "hello,$money";
7. Connection string $aa = "sdfs";$bb = "fsdfs"; $cc = $aa.$bb;
$cc = $cc."fsdfs";
8. About numbers
$n = 2.13;
$n = round($n); //3 Rounded
$n = 3.13141;
$n = round($n,3); //3.131 rounding of reserved digits
$n = number_format($n); //Add separator
$n = number_format($n,4);//Set the separator for the number of digits
9.Constant
define('NAME','VALUE');
echo NAME;
10.get is used to initiate data requests, and post users send data in one direction
11.$_REQUEST is a super global variable, which is a collection of $_POST and $_GET
12.isset() function is used to determine whether a variable has a value
13.empty() function is used to determine whether a variable is empty
14. Check whether it is a number using the is_numeric function
15. Array
$band[] = "sdfs";
$band[] = "sdfs";
$ band[] = "huhu";
$state = array(key1 => value1,key2 => value2....);
Key-value correspondence echo $state[key1];
foreach($array as $key =>$value){
}
Two-dimensional array
$array2 = (key1=>array1,.....);
16. Sorting
sort by value, reset the key value relationship
asort sorts by value and maintains key-value relationships
ksort sort by key
rsort,arsort,krsort reverse sorting
17. Loop judgment briefly
18.Included files
include(url);
require(url); //can be included multiple times
include_once(url);
require(url); //can only be included once
19. Processing html forms
if($isset($_POST['submitted'])){
}
else{
}
20.$page_title sets the title
21. Set up sticky form
22. Function reference js function
Note that an array can be returned
For example return array($avariable1,$avariable2);
You can set default parameters
function greet($name,$msg = "hello"){
}
23. If you want the variables within the function to be used externally, you can use global
function xxx(){
global $fsdf;
}