Review
Custom functions: Return values, parameter passing values (value passing and reference passing), scope (global and local, Hyper Global), static variables (function counter: static variable = value;).
anonymous function: Variable + ()
Pseudo type: Tells the user the type of the current data
Variable functions: Access through variable constructors
Data type judgment: Is_ data type
Data type conversions: Casts and auto-conversions, Settype and GetType
File contains: HTML layout and code reuse (multiplexing), include and require, path (absolute path and relative path)
Common system Functions
String functions, mathematical functions, time-date functions
String Functions
Strlen: Get string length, byte length
Bytes: Refers to the computer's storage unit, one byte = 8 bits
Characters: graphical symbols that are visible to the user, characters converted into bytes by character set
GBK: one character = 2 bytes
UTF-8: usually one character = 3 bytes, Special one character = 2/4 bytes
SUBSTR: String intercept, get string (intercept by byte)
String substr (target string, starting position of string [, intercept length])
The first letter of all strings in PHP occupies a position of 0
Strtolower: All characters are lowercase (for the English alphabet)
Strtoupper: All characters are capitalized
Strrev: String inversion (can only reverse English: only one byte in English storage), reverse by byte
Strpos: Find the position of the corresponding character (digital subscript) from the string, and start at the far left
Strrpos: As with Strpos, just start looking from the right side of the string
Commonly used with string interception (SUBSTR)
STRCHR: Similar to substr, intercept from a specified position until the last
STRRCHR (get file suffix name): As with STRCHR, just start looking for characters from the right
Trim: Remove the characters from both sides of the function by default, which removes contiguous content from both sides, not across content
String Trim (target string [, List of strings to be removed])
Typically: trim is used to exclude spaces or a specified character
Time-Date function
Time-date functions in PHP are powerful
Time: Gets the timestamp of the current time (int: Starting from GMT January 1, 1970 0:0 0 seconds) Number of seconds
Date: Time-serialization function that converts the specified timestamp to the display format of a given time date (random string: A professional format specifier), and if no timestamp is specified, the system uses the timestamp of the current time by default
Strtotime: The time-date format string is converted to the corresponding timestamp (as long as the correct English time expression can be converted)
Microtime: microsecond timestamp, returning different results according to different requirements
Mixed Microtime (Boolean type), can return the time of a floating-point number, or it can return an array (timestamp and microseconds)
Math-related functions
ABS: Absolute Value
Floor: Rounding Down
Ceil: Rounding up
Round: Rounding
Rand: Gets a random integer within the specified range
Mt_rand: Gets a random integer within a specified range (more efficient)
Array
Basic Concepts
1. What is an array?
A collection of data, where multiple information is saved by a variable.
2. Features of PHP arrays
A) There is no data type limit for data in PHP arrays
b) PHP array has no data length limit (data length, array element length)
c) The subscript of a PHP array element can be a number or a string
array Syntax
Defining Arrays
Mode 1:
Variable = array (); Empty array
Variable = array (1,2,3,4,5); Array inner elements are delimited with commas
Mode 2:
variable = [1,2,3,4,5];
Mode 3:
Variable [] = value;
Adding an array element
All array elements are added by using [] in the form of an array variable (dynamically added)
Array variable [] = value; Add an element to an array variable
Mode 1: The system automatically increases the subscript of the element: Key Name
Array variable [] = value
Method 2: Manually increment the subscript of the element: Key Name (value)
Method 3: Manually add the element subscript: string
Array Access
All arrays are accessed in the same way: they are accessed through the subscript of the array element
Syntax: variable name [' Subscript ']
PHP Array Classification
PHP Array classification based on: array subscript
Divided into three categories: indexed arrays, associative arrays, mixed arrays
Indexed array: The subscript of all array elements is all numbers
Associative arrays: The subscripts of all array elements are strings
Mixed arrays: Array subscripts have both numbers and strings
In PHP: Array subscript is unique, PHP subscript if the string is case-sensitive.
iterating through an array
Take out all the elements in the array
For Loop
Satisfy the basic condition: know the length of the array; the subscript of an array must be an index and increment from 0.
foreach Loop
The Foreach loop is designed to iterate through the elements of an array, taking the key names and values of the current array elements out and assigning them to the corresponding variables, respectively.
Syntax: foreach (array variable as [key name variable =>] Value variable) {
Use key name variables and value variables to output array element data corresponding to the operation
}
20141225 Array One