PHP removes the null element (array_filter) from the array ). PHP removes the null value element (array_filter) in the array. Previously, the null values in the array are strongly written into foreach or while, use these two syntax structures to delete the PHP element in the array to remove the null element (array_filter) in the array)
To put it bluntly, the null values removed from the array are strongly written into foreach or while. These two syntax structures are used to delete the empty elements in the array. The simple code is as follows:
$v){ if(!$v) unset($arr[$k]); }
It turns out that if the array is too large, the processing efficiency is not high. Because foreach is to copy the array of the current operation, each operation of foreach is a copy of a variable, if there are too many foreach in the page, it will be a great consumption.
When hanging out on the Internet, I saw a prompt to use array_filter. so I opened the manual and looked at it. I found that I had been keeping a guard of Baoshan, but I didn't know how to use it.
The array_filter function uses the callback function to filter the array. If no callback function is available, items with the value of false in the array are deleted by default. Example:
'foo', 1 => false, 2 => -1, 3 => NULL, 4 => '');print_r(array_filter($entry));
The output value is:
Array
(
[0] => foo
[2] =>-1
)
Suggestion: The most important two chapters in PHP should be array operations and string operations. the functions in these two chapters must be skillful. you can check other functions when using them.
Articles you may be interested in
- Php clears the null element in the array.
- Php searches for the existence of a value in the array (in_array (), array_search (), array_key_exists ())
- How does php delete the first and last elements of an array?
- Php pushes an element to the array header (array_unshift usage)
- PHP merges arrays + and array_merge
- Php retrieves the last element of the array
- Remove duplicate values and array_unique functions from two-dimensional arrays
- Reasons why PHP adds a backslash before the quotation mark and how PHP removes the backslash, there are three ways to disable the php magic quotation mark
Explain (array_filter). in the past, when the null values of the array were removed, they both strongly written foreach or while, and these two syntax structures were used to delete...