Working with HTML forms
<input type= "text" name= "City"/>
by $_request[' city '; access, $_request city The spelling must be exactly the same (Name property value)
$_request is a special variable type, called a Super global variable (detailed later)
if (condition) {
Do something
}elseif (condition2) {
Do something else
}else{
Do something different
}
The Isset () function is used to detect whether a variable is set, except NULL, which is considered true (including 0 false and empty string, null means no value set)
The empty () function checks if a variable has a null value: empty string 0 null FALSE
PHP supports indexed array (numeric as key) associative array (string as key)
Printing a string with an associative array can result in an error
echo "Il is $states [' il ']." Wrong
Correct: Enclose the array with {}
echo "Il is {$states [' il ']}."
Hyper-Global Array
PHP default multiple pre-defined arrays: $_get, $_post, $_request, $_server, $_EVN, $_session, $_cookie
$_get stores all the variables and values sent to the PHP script via the Get method
To test whether the submitted value is a number, use the function is_numeric () function
Create an array
$band []= ' Bret ';
$band [' Fan ']= ' Bret ';
You can also use the array () function
$states =array (' IA ' = ' Iowa ', ' MD ' = ' Maryland ');
$artists =array (' Sun ', ' Mon ', ' Tue ');
Create a contiguous array, using the range () function
$ten =range (1,10);
$alphabet =range (a,z);
Accessing an array can use the Foreach Loop
foreach ($array as $value) {
Do something
}
foreach ($array as $key = = $value) {
echo "The value at $key is $value.";
}
Count () determines the number of elements in the array
$num =count ($array);
converting arrays and strings to each other
$array =explode (separator, $string);
$string =implode (glue, $array);
Array sorting
Sort () Sorts by value, discarding the original key
Asort () Sort by value, keeping the original key
Ksort () Key sorting
Arsort () by alphabetical order
Kasort () sorted by value order, key saved unchanged
Shuffle () random order
Create a Dynamic Web site
PHP has 4 functions for external files include () include_once () require () require_once ()
The result of any of these functions is to get all the contents of the containing file and delete the file in the script that invokes the function, and PHP will treat the containing code as HTML and send it directly to the browse
Relative path (the current script is in the Ex1 folder)
Include ('.. /ex2/file.php ');//2 periods to move to the previous level of the folder
The include () and require () functions behave the same when they are working correctly, and there are different ways to handle failure
Include () print error, script continues to run
Require () print error, script stops running
*_once () indicates that only one time is included
Variables defined in the code before include () can be used by the include () code
The variables in the include () can also be used by the code after the include ()
The function has its own scope, that is, the function cannot use external variables, external variables cannot be used externally.
You can use the Hyper global variable $_get $_post $_request access, or you can add elements to the $globals array, and generally avoid using global variables
PHP and MySQL Dynamic Web Development 2