This article is mainly to share with you the PHP system functions of the example of the detailed, I hope to let you have a more in-depth understanding of system functions.
Array-related functions:
Key/value operations for arrays:
1.array_values ($arr)
Returns all values in an array and creates a numeric index on them
2.array_keys ($arr [, ' Value ' [, true]])
Returns all the key names in the array
Give ' value ' the key that takes out the value
Give ' true ' to indicate the value is determined by = =
3.in_array (' value ', $arr [, True])
Determine if there is a value in the array
To true means to judge by = =
4.array_key_exists (' key ', $arr)
Determine if there is a key in the array
5.array_flip ($arr)
Key value Exchange
6.array_reverse ($arr [, True])
Invert an array
True indicates that the original numeric subscript is retained
Statistics and Uniqueness:
Count ($arr [, 1]) counts the number of array elements
Give 1 the number of recursive statistics arrays (not commonly used)
Array_count_values ($arr) Count of occurrences of values in an array
Note: only string or int can be counted, otherwise the error
Substr_count ($str, ', ') counts the number of occurrences of a character string.
Array_unique ($arr) removes duplicate elements from the array, preserving the previous values
To filter an array using a callback function:
Array_filter ($arr, callback);
Passes each value in the array to the callback function, returns true in the callback function, preserves the value, and returns false without preserving
Array sort function:
1.sort () from small to large, do not reserve the key (ascending) 2.rsort () from large to small, do not reserve the key (descending) 3.asort () from Small to large, reserved key (Ascending) 4. Arsort () from large to small, reserved key (Descending) 5.ksort () by key, from small to large (ascending) 5.krsort () by key, from large to small (descending)
Note: You may have unpredictable results when sorting mixed type values
Split, merge, and set of folios:
1.array_slice (cut who, start position [, cut a few [, whether to keep the key]])
Cut who: Array to cut
Start position: Starting at 0, the element where the start position will be preserved
[Cut a few]: when not given, the default cut to the last
[Leave key]: default false, not reserved; True to preserve original key
2.array_splice (& Cut who, start position [, cut a few [, substitute]])
Cut who: the array to be cut, is the reference to pass
Start position: Starting at 0, the element where the start position will be preserved
[Cut a few]: when not given, the default cut to the last
[Substitute]: insert a substitute into the original array without preserving the key
3.array_combine (key array, array of values)
Using the value of the key array as the key, the value of the value array as the value;
Requires two arrays to be the same length, otherwise error and return false
4.array_merge ($arr 1[, $arr 2, $ ...])
merging n arrays;
Note: The key of the string with the same name will later overwrite the previous
Extensions: The plus sign can also combine arrays; keys with the same name retain the previous values
5.array_intersect ($arr 1, $arr 2[, $ ...])
Returns the value in the N array, and the subscript retains the previous
6.array_diff ($arr 1, $arr 2[, $ ...])
Returns an element that is not in the other array in the $ARR1, and the subscript remains unchanged
Arrays and data structures:
The last element in the Array_pop () pop-up array array_shift () pops the first element in the array Array_push () appends 1 or more elements to the array Array_ Unshift () Append 1 or more elements to the front of the array
Data structure: a container for storing
Queue: Equivalent to pipe, FIFO
Stack: equivalent to a cup, LIFO
Pointer-related
Current () Returns the value of the currently pointer to the array next () moves the pointer of the array to the next and returns its value prev () moves the pointer of the array to the previous and returns its value end () Moves the pointer to the end of the array and returns the last value reset () resets the pointer to the array
Randomly scrambled arrays
Range () generates an array of the specified range
Shuffle () random scrambled array
String-related
String Common output:
echo outputs one or more strings
Print output A string
Echo and print are a language structure, not a function;
For simple data such as the output string
Print_r printing variables easy to understand information
is to look at the values of the various types of variables
Var_dump information about the print variable
You can see any type of value and type
printf () formatted output string
%s represents a string
%b means binary number
%o Indicates octal number
%d = decimal number
%x = hexadecimal number
%c means that it is an ASCII code value
Percent of a pure percentage
sprintf () ibid., just return the result instead of the output
The difference between Echo and Print_r in the written question:
1.echo is a language structure, not a function, so the efficiency is slightly higher;
2.echo can output multiple strings at the same time, and Print_r can not
3.echo can only output simple data types, while Print_r may print composite types of data, such as arrays, objects, etc.
Remove and fill:
LTrim ($str [, ' List of characters to be removed '])
Remove left space by default
RTrim ($str [, ' List of characters to be removed '])
Remove the right space by default
Trim ($str [, ' List of characters to be removed '])
Default to remove spaces on both sides
Str_pad ($str, length, filler)
Fills another string with a string for the specified length
String-Case Conversions:
Convert strtolower () to lowercase
Convert Strtoupper () to uppercase
Ucfirst () Capitalize first letter
Ucwords () capitalize the first letter of the word (space-sensitive word)
Functions related to HTML tag processing:
Htmlspecialchars ()
Convert special characters to Entities
Htmlentities () ibid., Basic No
The old version of the Chinese will be transferred together
Strip_tags ()
Remove HTML tags
Nl2br
Convert \ n line break to <br> line break
string inversion, length, and encryption:
Strrev ()
Display a string upside down
Str_shuffle ()
Randomly disrupts a string
Strlen ()
The length of the statistic string, utf-8 in Chinese 3 bytes
MD5 ()
Encrypt the string to get a 32-bit encrypted string
Number_format ()
Format a number
Can only be one, 2, or 4 parameters
string comparison function: shorthand for cmp:compare, meaning of comparison
strcmp ()
Compare two strings (case sensitive)
STRNCMP ()
Compares several characters at the beginning of a string (case-sensitive)
STRCASECMP ()
Compare two strings (case insensitive)
STRNCASECMP ()
Compares several characters at the beginning of a string (case-insensitive)
Cutting and connecting strings:
Explode (' cutting character ', $str)
Uses a string to split another string, returning an array
Implode (' connector ', $arr)
Joins a one-dimensional array with the specified string, returning a string
Join ()
Aliases for implode
String interception:
SUBSTR ($str, starting position, length of cut);
The start position starts at 0, and the negative number is inverted!
The string also has subscripts:
You can remove the value of a string as an array by subscript
However, it is best not to use Chinese
Search for Strings:
Hint: Usage unification is ($STR, ' substring to find ');
1.strstr ($str, ' string to find ');
Returns the string starting at the first occurrence of the substring, to the end;
There are also individual names: STRCHR
2.STRRCHR returns the string that begins at the last occurrence of the substring, to the end of the
3.strpos ($str, ' string to find ')
Returns the index position of the first occurrence of the substring, starting at 0;
Note: 1 Chinese characters are 3 bytes
4.strrpos ($str, ' string to find ')
Returns the index position of the last occurrence of the substring
5.stripos () case-insensitive Strpos
Substitution of strings
Str_replace (' Find what ', ' change what ', ' where to change ');
Mathematical functions
Ceil () Rounding up floor () rounded down round () round Max () max min () min. Mt_rand () Random Number
Related recommendations:
Summary of common system functions in PHP
10 article recommendations for file system functions
PHP Common system Functions Daquan