14. array:
Indexed arrays:
The subscript is the beginning of the number.
$arr = [' A ', ' B ', ' C ', ' n ';
Associative arrays:
$arr = [
' A ' = ' B ',
' C ' = ' d ';
' E ' = ' f '
];
Two-dimensional arrays:
Associations and indexes are mixed.
$arr = [
' A ',
' B ',
' C ',
' d ' = [
' E ' = ' h ',
' F ',
' G '
],
' I ',
];
Three-dimensional arrays and multidimensional arrays.
1<?PHP2 $arr= [1,2,3,4,5,6,7,8];3 Var_dump($arr);4 Echo' <br/> ';5 $arr 1= [' 5 ' = ' A ', ' B ', ' C ', ' d '];6 Var_dump($arr 1);7 Echo' <br/> ';8 $arr 2= [9' Bond ' = ' Agent movie ',Ten' Wu Town ' and ' Police gangster movie ', One' Lam ching ying ' = ' zombie movie ']; A Var_dump($arr 2); - Echo' <br/> '; - $arr 3= [' super hero ' = + [ the' Ant man ', ' Iron Man ', ' Spider-Man ', -' Marvel series ' - ]; - Var_dump($arr 3); + Echo' <br/> '; - $arr 4= [' head ' = ' [ +' Commander in succession ' = [' Private one ', ' private second '], ' two company commander ', ' three company commander ' A ] at ]; - Var_dump($arr 4); -?>
Gets the value in the array:
1 <? PHP 2 $arr = [' A ', ' B ', ' C ', ' d ']; 3 Echo $arr [1]; 4 ?>
Add a single element:
1 <? PHP 2 $arr = [' A ', ' B ', ' C ', ' d ']; 3 $arr [4] = ' E '; 4 Var_dump ($arr); 5 ?>
To delete an element:
1 <? PHP 2 $arr [' A ', ' B ', ' C ', ' d ']; 3 unset ($arr[2]); 4 Var_dump ($arr); 5 ?>
To modify an element:
1 <? PHP 2 $arr = [' A ', ' B ', ' C ', ' d ']; 3 $arr [0] = ' A '; 4 Var_dump ($arr); 5 ?>
Two-dimensional array definitions:
1 <? PHP 2 $arr [3 ' Ant Man ', ' Iron Man ', ' Spider-Man ', ' Thor '],4 ' Marvel series ']; 5 Echo $arr [' Super heroes '] [1]; 6 ?>
Three-dimensional array definition:
1 <? PHP 2 $arr = [' head ' = [' Commander in chief ' = ' "Private One ', ' private second '], ' two company commander ']]3var_dump($arr [' Colonel '] [' Commander in succession '] [0]); 4 ?>
1<?PHP2 $arr= [1,2,3,4,5,6,7,8,9];3 $sum= 0;4 $num=Count($arr);5 for($i= 0;$i<$num;$i++){6 $sum=$sum+$arr[$i];}7 Echo $sum;8?>
1<?PHP2 $arr= [' a ' = = ' aaa ', ' b ' = ' BBB ', ' c ' = ' CCC '];3 foreach($arr as $key=$value) {4 Echo $key.‘ ---‘.$value.‘ <br/> ';}5 Echo' <br/> ';6 $arr 1= [' 1 ', ' 2 ', ' 3 ', ' 4 '];7 List($a,$b,$d,$c); =$arr 1;8 Echo $a,$b,$c,$d;9 Echo' <br/> ';Ten $arr 2= [' A ', ' B ', ' C ', ' d ']; One Var_dump( each($arr 2)); A Var_dump( each($arr 2)); - Var_dump( each($arr 2)); - Var_dump( each($arr 2)); the Echo' <br/> '; - $arr 3= [' A ', ' B ', ' C ', ' d ', ' e ']; - while(List($key,$val) = each($arr 3)) { - Echo $key.‘ ---‘.$val.‘ <br/> ';} +?>
15. Hyper-Global array:
$_get $_post $_request $_serve $_session $_cookie
About Get method= "Get/post"
$GET: If you do not write the submission method in the form, the default is GET pass through the URL
If you want to use post to pass the parameter, you must specify the POST method.
You use get to submit you must accept with get.
$POST: You use post to submit you must use post to accept $_post[' username ']
$_request: can accept post submitted to also accept get submitted.
Suggestion: In what way you submit, in what manner to accept.
$_server
$_server[' REMOTE_ADDR '];//get IP address
$_server[' Http_referer ']; Parent Source Page
1 <HTML>2 <Head>3 <MetaCharSet= "Utf-8" />4 <title>Hyper-Global Array</title>5 </Head>6 <Body>7 <formAction= "login.php"Method= "Get">8User name:<inputtype= "text"name= "username" /><BR/>9Password:<inputtype= "Password"name= "Password" /><BR/>Ten <inputtype= "Submit"value= "Login" /><BR/> One </form> A </Body> - </HTML>
1 <? PHP 2 Var_dump ($_get) 3 ?>
1<?PHP2 $username=$_get[' username '];3 $password=$_get[' Password '];4 $user= ' John Doe ';5 $pass= ' 123123 ';6 if($username==$user&&$password==$pass) {7 Echo' Landing success ';}8 Else{' Login failed ';}9?>
16. Date Function:
Use:
Registration time
Logon Hours
Time to exit
Time of posting
Time of reply
When the post was modified
Time the post was deleted
Time of purchase
Time of order
..........
Timestamp: The time stamp refers to the total number of seconds from GMT January 1, 1970 00 minutes 00 seconds (Beijing time January 1, 1970 08:00 00 seconds) to the present. In layman's words, a timestamp is a complete verifiable data that can represent a data that already exists at a specific point in time. His main proposal is to provide users with an electronic evidence to prove the timing of certain data generated by the user. In practical applications, it can be used in all aspects of including e-commerce, financial activities, and in particular can be used to support public key Infrastructure "non-repudiation" services.
January 1, 1970 zero 0 minutes 0 seconds-now
The number of seconds left
Set the time zone:
Date_default_timezone_set ();//PRC
Modify Date.timezone = "UTC" in php.ini
Change to Date.timezone = "PRC".
1 <? PHP 2 date_default_timezone_set (' PRC ');3$timetime(); 4 Echo Date (' y-m-d h:i:s ',$time); 5 ?>
Basic knowledge of PHP (iv)