1 Preface
Recently learning PHP, the last section summarizes the PHP development environment to build the [PHP] 1, from the installation and development environment to (village B) to do a cool landing application. This section summarizes the core basic grammar of PHP, basically written in rough outline, can be counted as the core outline!
2 new environment
1, configure the root directory can be modified by modifying the configuration file
2. root directory used to store the application source code and resources
3, PHP code must be placed in the < In PHP?>
4. Variables can only start with Chinese characters, letters, and underscores
5. Output: Echo
6, coding problems: the creation of the files are encoded, we generally use UTF-8, but the system default is the other code, so to write in PHP code (in the head)
7. Note://or/**/
8, garbage Collection: When the program runs out, will be automatically recycled, if you want to release early, you can use Unset ($XXX)
3 Data types
Bool:true, False
Integer
String: You can use single or double quotation marks (the variables in single quotes are not resolved)
Float
Object
Array: $color =[' red ', ' balck ', ' Blue '; $color [0]
Resource: Pictures and other resources
Null: already has a variable but has no value, is null
4 operator
+ - * / %
. Connection string
= = = all equals
! = = Not all equals
PS:= = is the value equal, for example 0== ' 0 '; = = = value and type are equal
5 Process Control
if () {...} ElseIf (){...} Else{...}
Die and exit are all stop a script (to this end, the script is executed)
6 functions
Generic function definition: function name () {...}
Function call: function name ();
Define functions with Parameters: function name (parameter 1, parameter 2, Parameter 3, ...) {...}
return value: Return (① exit function; ② returns a value from inside a function to the calling environment)
1 function GetName () 2 {3 $name= ' Tom '; 4 return $name ; 5 }67$abc=getname ();
7 Scope of variables
| 1 |
Super Global variables |
PHP comes with a |
All positions Valid |
| 2 |
Global variables |
Custom variables, classes, and functions outside of the script |
Entire script, without functions inside |
| 3 |
Local variables |
function internally defined by the |
Inside the function |
8 Common functions
1. Output:
--
| Var_dump output Type, value and other information (for general debugging purposes)
| Print_r
| Die
| Exit Die and exit stop when output
--
2. Time:
--
| Time timestamp (number of seconds from January 1, 1970 to present)
| Date formatted dates: Date (' y-m-d h:i:s ')
--
3. Contains: (contains another PHP file)
--
| Include if the file does not exist and can continue to run
| Include_once if included more than once, only one time is included
| Require cannot continue to run if it does not exist
| Require_once
--
4. String manipulation
--
| Strlen
| Strpos
| SUBSTR (string, start position, length) docs.php.net can view various functions
| Trim, LTrim, rtrim to remove spaces before and after a string
| Str_rplace (substituted substring, replaced by XXX substring, string)
--
5. Array manipulation related functions
--
| Count
| Delete after Array_push
| Eject after Array_pop
| Insert before Array_unshift
| Array_shift Front Popup
| Unique
| Sort
| Shuffle upset
--
9 Array Advanced
1. Array Traversal:
foreach, for, while, Do_while
1 foreach ($coloras$k=$v) 2 {3 Echo $k; // Subscript 4 Echo $v; // value 5 }
2, Multidimensional array: (a value in the array is still an array)
$color =[' red ', ' black ', ' blue ', [' ble ', 2,[3, ' ble ']];
$color [3][2][1];
3. Associative arrays:
--
| Index array <--subscript from 0 increments
| Associative array <--subscript can be arbitrary
--
$people =[' name ' = ' Tom ', ' age ' =>10];
^ ^
Subscript value
[Introduction to PHP] 2, basic core Grammar outline