Date action
For ease of storage, comparison, and delivery, we typically use the Strtotime () function to convert a date to a UNIX timestamp and use the date () function to convert the date to the usual time format only when displayed to the user.
The strtotime () function resolves the date-time description of any English text to a Unix timestamp
eg
Output:
1138614504
1128290400
1138632504
1139219304
1139503709
1139180400
1138489200
The date () function converts the timestamp to the usual 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 a part of a string and you need to use the Intercept substr () function of the string
The substr () function returns part of the string
Grammar:
SUBSTR (String,start,length)
eg
echo substr ("Hello world!", 6,5);
Output:
World
Array operations
Here are two very useful functions:
Array_unique () to move 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 unchanged.
Array_filter () to delete an empty element in an array
Grammar:
Array Array_filter (array $input [, callable $callback = "])
In turn, each value in the input array is passed to the callback function. 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 an array to loop
Callback for the callback function used, if no callback function is provided, all entries in input that are equivalent to FALSE are deleted (you can use this to delete an element that is empty in the array).
EG1:
1, "B" =>2, "C" =>3, "D" =>4, "E" =>5);
echo "ODD: \ n";
Print_r (Array_filter ($array 1, "odd"));
? >
Output:
ODD:
Array
(
[A] => 1
[C] => 3
[E] => 5
)
EG2:
' foo ',
1 => false,
2 =>-1,
3 => null,
4 => '
);
Print_r (Array_filter ($entry));
>
Output:
Array
(
[0] => foo
[2] =>-1
)