String functions
strlen (string);
Gets the length of the string, where the length refers to the byte length of the string;!! The English alphabet and symbols in the Utf-8 account for 1 bytes, while Chinese is 3 bytes.
SUBSTR (String,number1,number2)
Intercept the string, Number1 is the beginning of the intercept position, starting at 0, Number2 is the length of the Intercept.
Strtolower | Strtoupper
Lowercase the English letters in a string | Capitalize the English letters in the string
Strrev
The inverse of the string is reversed by byte, so the inverted character is garbled.
Strpos (a character of string,string)
POS is the meaning of position position,
So the function is to find and return from left to right the starting position of a character in the string!
Strrpos (a character of string,string)
Search from right to left! You can also think of the position of the last occurrence of the character from left to right!
STRCHR (a character of string,string)
It is also the intercept string, which is the entire string from left to right to intercept the specified position (the position of the specified character).
STRRCHR (a character of string,string)
is to intercept the entire string from right to left, starting at the specified position (the position of the specified character)!
Trim (string,\t\n\r\0\x08)
This function strips out the trailing white space characters and returns the result. The trailing argument is to delete the space.
str_repeat (String,number)
The first one is the string that needs to be repeated, the second is the number of repetitions
Time function
Time
Time stamp, Greenwich January 1, 1970 0 o'clock, the number of seconds to now!
Date
Use the time format placeholder to format the specified timestamp in the form of a corresponding format!
Year: Y Month: M day: D: H min: I seconds: s
Syntax: Date ("String with Format placeholder", timestamp)
Where the second parameter (timestamp) can be omitted, the default value is the current timestamp!
Strtotime
Convert the time string in an English format to a timestamp!
Microtime ()
Can be used to test the efficiency of code Execution!
Get a subtle timestamp string (string type), or add a parameter of True (the default value is False) and get a microsecond time (floating point type)
Array
Creating an array syntax
$arr = Array (
string1 = string,
string2 = string,
..............................
STRINGN = string
)
$arr [' string1 '] = string;
$arr [' string2 '] = string;
..........................................
$arr [' stringn '] = string;
Traversal of an array
In addition to iterating with a for loop, you can also use foreach to traverse
Syntax foreach (array name as $key (key variable) = = $value (value variable)) {
Loop body//action on value variables and key variables
}
The key variable is the index value of the array.
Array functions
Next, we'll talk about common and common array functions.
Count:
Calculates and returns the number of elements in an array or the number of attributes in an Object!
When you calculate a multidimensional array, you add the number of one-dimensional arrays and the number of arrays in one-dimensional array elements.
Count also has a second parameter, which defaults to false and, if true, supports recursive statistics.
Range:
Create an array containing the specified range of cells, with three parameter 1, beginning character or number, 2, ending character or number, 3, step: Jump a few characters or numbers at a time.
Array_merge:
Merges several arrays into an array. The values in an array are appended to the back of the previous array. In addition, the operator + can also implement the merging of arrays;
Array_Rand:
Randomly extracts the keys of several elements within an array and returns an indexed array!
Requires two parameters: 1, array name 2, the number of extracts!! Omitting the second parameter defaults to 1.
Shuffle
Scrambled an array with only one parameter 1. Array name
Array_keys
Gets the key for all elements, returns an indexed array with only one parameter 1. Array name
Array_values
Gets the value of all elements, returns an indexed array with only one parameter 1. Array name
Array_combine
There are two parameters, 1 array names, this array as the key of the new array, 2, the array name, the array as the value of the new array
Makes up a new array, requiring the same number of two arrays.
Array_flip
Swap the keys and values of an array
In_array
Determine if a data is the value of an element inside an array! Returns a Boolean value!
Two parameters 1 specific data; 2 array name.
Array_key_existe:
Determines whether a key exists in an array, returns a Boolean value
Two parameters 1 specific data; 2 array name.
Array_search
Searches for the value of an element within an array and returns its subscript value
Two parameter 1 specific value; 2 array name
Array_chunk
There are two parameter 1 array names, and 2 of the values to be merged
To synthesize an array of values in an array, the number of values to be synthesized depends on the second argument
Implode
Concatenate all the values of an array element into a string using a specified delimiter!
Two parameters
1, separator, here can be omitted, if omitted, that is no delimiter 2, the array name
Explode
A string, using the delimiter in it, splits it into multiple parts to form an array!
Two parameters
1, delimiter 2, String!
Extract
Each element in the array is transformed into a variable whose name is the key to the array element, and the value of the variable is the value of the array element!
Only one parameter, 1, array name
Compact
Using multiple variables to form an array, the key of the array element is the name of the variable, and the value of the array element is the value of the variable!
Array_map
Each element of an array is called by the system to a function!
Array_push
Press one or more data into the tail of the array!
Array_pop:
POPs the last data of the array
Array_unshift:
Add data from the front of the array
Array_shift:
Eject data from the front of the array
Sort
The elements in an array are sorted in ascending order, that is, from low to high!
After sorting, the keys of the original array are lost and an indexed array is regenerated!
Asort
It is also sorted in ascending order, but the previous key value pair will be preserved after sorting!
Rsort
The values of the array elements are sorted in descending order, that is, from high to Low:
An indexed array is regenerated after sorting!
Arstort
It is also sorted in descending order, only the previous key value pairs will be preserved!
Getting Started with PHP part4