Date Operation
To facilitate storage, comparison, and delivery, we often need to use the Strtotime () function to convert dates into Unix timestamps, and use the date () function to convert dates to the usual time format only when displayed to the user.
The strtotime () function resolves the datetime description of any English text to a Unix timestamp
eg
Output:
1138614504
1128290400
1138632504
1139219304
1139503709
1139180400
1138489200
The date () function converts a timestamp to a common date format
eg
echo Date (' y-m-d h:i:s ', "1138614504");
Output:
2006-01-30 17:48:24
String manipulation
Sometimes you need to get part of a string, you need to use the Intercept substr () function of the string
SUBSTR () function returns part of a string
Grammar:
SUBSTR (String,start,length)
eg
echo substr ("Hello world!", 6,5);
Output:
World
Array manipulation
Here are two very useful functions:
Array_unique () Moves the number of identical elements in the divisor group
When the values of several array elements are equal, only the first element is preserved, and the other elements are deleted.
The key name in the returned array is not changed.
Array_filter () to delete an empty element in the array
Grammar:
Array Array_filter (array $input [, callable $callback = ""])
Each value in the input array is passed to the callback function in turn. If the callback function returns TRUE, the current value of the input array is included in the returned result array. The key name of the array remains unchanged.
Input is the array to loop
Callback is the callback function that is used, and if no callback function is provided, all entries in input that are equivalent to FALSE (which can be used to delete elements that are empty in the array) are removed.
EG1:
1, "B" =>2, "C" =>3, "D" =>4, "E" =>5); echo "ODD: \ n";p rint_r (Array_filter ($array 1, "ODD"));? >
Output:
ODD:
Array
(
[A] = 1
[C] = 3
[E] = 5
)
EG2:
' foo ', 1 = False, 2 = 1, 3 = null, 4 = ' );p rint_r (Array_filter ($entry));? >
Output:
Array
(
[0] = foo
[2] =-1
)