The similarities and differences of include and require: The same point: can introduce other PHP files. Different points: include when a file error is introduced, only a warning appears, but the program continues to execute. And when require error, it will complain, the program terminated. generally use include_once and require_once, without using include and require. The statement that introduces the file is placed at the front, which is similar to the C language. PHP variables are case-sensitive, but function names are case-insensitive. and cannot begin with a number. For example, ABC and ABC are the same, and if such two functions exist in a file, an error will be found. Local variables and global variables under the same name of the situation analysis; See the following code: $a = 45; function ABC () {//definition function $a + + } ABC (); Call function echo ' $a = '. $a; What is the output of the result? The result is still 45, why? In the function body is the local variable, and the external variable $a the same name, but not the same variable, but two completely irrelevant variables. The variable $a within the function is released as soon as the function is executed. The output is still an external variable, and if you want to use an external variable (global variable) in the body of the function, then add the global declaration before the variable with the same name inside it. In fact, in the compiler's view, declared as global is actually the address of the variable with the external name assigned to the local variable, when the internal variable and the external name variable is the same address, so naturally become the same variable. In a function body, a local variable that is not declared as global is used as a local variable, and the scope is in the function body. For example, the following code output is 45 instead of 55. $a = 45; function ABC ($a) {//definition function $a + + } ABC ($a); Call function echo ' $a = '. $a; in PHP There are three levels of errors: First-level error: Notice, the lightest error, you can also perform second level error: Warn, warning, and can also execute the third level error: Error, the program can not be carried out, This error is the most serious error unset function Commentary: (PHP 3, PHP 4) unset--Releases the given variable, which can be released when we do not want to use the variable. description void unset (Mixedvar [, Mixed var [, ...]]) unset () destroys the specified variable. Note in PHP 3, unset () returns True (actually an integer value of 1), whereas in PHP 4, unset () is no longer a real function: it is now a statement. So that there is no return value, trying to get the return value of unset () will result in a parse error. If you unset () a global variable in a function, only the local variable is destroyed, and the variable in the calling environment retains the same value that preceded the call to Unset (). That is, the global variable remains intact outside the function. If you unset () a variable passed by reference in a function, only the local variable is destroyed, and the variable in the calling environment retains the same value as before the unset (). That is, a formal parameter is a case of an address character. PHP is a bit like C, does not support polymorphism, does not allow the existence of a function of the same name, but more flexible for formal parameters, you can not write or write less than a few parameter values when called. You can also assign a default value to a parameter. For example, function Diymethod ($a, $b =3) is to give the formal parameter default value of 3, PHP function is the default value transfer, to use reference delivery (address delivery), before the formal parameters with the address & can be. A reference pass is actually a bit equivalent to changing the incoming argument of a parameter's call to that function into a global variable. Although there is no global declaration. Reference passing changes the value of the incoming parameter! Note, however, that the reference here is not a pointer to C. Because the pointer itself is a variable, and PHP's reference is actually a variable alias, plainly, is an address can have more than one variable name. Referencing in PHP means accessing the contents of the same variable with a different name. When declaring a variable with global $var, a reference to a global variable is actually established. PHP variables, constantsDefine method 1. Define constants define ("CONSTANT", "Hello world."); Constants can only contain scalar data (boolean,integer,float and string). When calling a constant, simply get the value of the constant with the name, not the "$" symbol, such as:echoconstant; Note: Constants and (global) variables in different namespaces. This means that, for example, TRUE and $TRUE are different. 2. Ordinary variable $a = "Hello"; 3. Variable variable (using two dollar sign ($)) $ $a = "World"; two variables are defined: $a content is "hello" and $hello The content is "world". Therefore, it can be expressed as: echo "$a ${$a}", or echo "$a $hello"; they all output: Hello world to use variable variables in arrays, you must solve an ambiguous problem. This is when you write $ $a [1], the parser needs to know if you want to $a [1] as a variable, or if you want $ $a as a variable and take out the value indexed by [1] in the variable. The syntax for solving this problem is to use the ${$a [1]} for the first case, with ${$a}[1] for the second case. 4. Static variables Inside functions $a =0; Note: Assigning a value to an expression in a declaration can result in parsing errors such as static $a =3+3; (error) A static variable exists only in a local function field (within a function), and the value of the variable is not lost after the function is executed, and can be used for recursive invocation 5. Global variables The global variables defined in the function body, which can be used outside of the function body, Global variables defined outside the function body cannot be used in the function body, and accessing variables globally can be: with special PHP custom $GLOBALS arrays such as: $GLOBALS ["b"] = $GLOBALS ["a"] + $GLOBALS ["B"];& nbsp A real global variable imported with the global statement in a function field actually creates a reference to global variables global $obj; Note: the static and global definitions for variables are implemented in an applied way 6. Assign a value to a variable: Transfer address Assignment (simple reference): $bar = & $foo; Add & sign to the variable to be assigned change the new variable will affect the original variable, this assignment is faster NOTE: Only named variables can pass address assignment NOTE: if $bar = & $a; $ Bar = & $foo; Changing the value of $bar can only change the value of variable foo without changing the value of a (reference changed) 7.PHP Super global variable $globals: contains a reference to a variable in the global scope that is valid for each current script. The key of the array is the name of the global variable. $GLOBALS array is present starting with PHP 3. $_server: Variables are set by the WEB server or directly associated with the execution environment of the current script. Similar to the old array $HTTP _server_vars array (still valid, but opposed to use). $_get: A variable submitted to a script via an HTTP get method. $_post: A variable submitted to the script via the HTTP POST method. $_COOKIE: Variable submitted to script via HTTP cookie method. $_files: A variable submitted to the script via an HTTP POST file upload. File Upload form to have enctype= "Multipart/form-data" $_env: Execution Environment submitted to the script variable. $_request: A variable submitted to a script via the get,post and COOKIE mechanisms, so the array is not trustworthy. The existence of all variables contained in the array and the order of the variables are defined according to the Variables_order configuration instructions in php.ini. The array does not directly simulate an earlier version of PHP4.1.0. See Import_request_variables (). NOTE: since PHP 4.3.0, the file information in $_files no longer exists in $_request. $_session: Variables currently registered to the script session. How to disable Phpinfo (): php.ini disable_functions = phpinfo () Restart the Web server. &nBsp Constants Constants in PHP can only be define (constant name, constant value); constants can contain only scalar data (Boolean,integer,float and string). can simply get the value of the constant by specifying its name, and do not precede the constant with the $ symbol. If the constant name is dynamic, you can also use functions constant () to read the value of the constant. You can get a list of all the defined constants with Get_defined_constants (). Note: Constants and (global) variables are in different namespaces. This means that, for example, TRUE and $TRUE are different. If you use an undefined constant, PHP assumes that you want the name of the constant itself, as if it were called with a string (CONSTANT corresponds to "CONSTANT"). A e_notice level error is emitted at this time. See the Manual for why $w 3sky[bar] is wrong (unless you define bar as a constant with define ()). If you only want to check whether a constant is defined, use the defined () function. Constants and variables different: * Constants are not preceded by a dollar sign ($); * Constants can only be defined with the Define () function, and cannot be defined and accessed anywhere by means of an assignment statement; * Constant without regard to the rules of variable scope; * Constants cannot be redefined or undefined once defined; * Constants can only be scalar. Definition Constants php define ("CONSTANT", "Helloworld."); Echo CONSTANT; Outputs "Helloworld." Echo Constant; Outputs "Constant" and issues a notice. ?> diving competition, scored 10 judges, removed a maximum score and a minimum score, and then asked the remaining judges to sum the score of the average divided into the athlete's score, The test output is given to the highest scoring judges and to the judges with the lowest points and the athlete's score. The answers are as follows:
<?php $arr = Array ("Arial" =>12, "MS" =>9.0, "OK" =>7.1, "song" =>5.0, "bold" =>3.8, "Know" =>2.7, "wow"
=>1.7, "Serial" =>7.9, "Moder" =>7.6, "Froke" =>6.7);
function Getminmax ($arr, $k =true) {//$k is true to output the minimum value, false to output the maximum, and an average $num = $arr ["Arial"]; $sum =0; $s = "Arial";
foreach ($arr as $i => $value) {if ($k) {if ($value < $num) {
$num = $value; $s = $i;
}}else {if ($value > $num) {$num = $value; $s = $i;
}} $sum = Array_sum ($arr);
Return Array ($sum, $num, $s);
$NEWARR =getminmax ($arr, true);
$sum = $NEWARR [0]-$newArr [1]; Echo ' The lowest degree people is '. $NEWARR [2]. "
<br/> ";
Unset ($NEWARR);
$NEWARR =getminmax ($arr, false);
$sum-= $NEWARR [1];
Echo ' <br/>the highest degree people is '. $NEWARR [2]; Echo ' <br/>the average degree is '. $sum/(Count ($arr)-2);
?>