php array array_filter function and array_slice function
WBOYOriginal
2016-07-28 08:26:351122browse
/*
array_filter() uses the callback function to filter the cells in the array
array _filter(array,function)
Parameter description: If the custom filter function returns true, the current value of the operated array will be included in the returned result array,
and the result will be formed into a new array, if the original array is An associative array, the keys remain unchanged.
*/
function delEmpty($val) {
if($val=== "" || $val === "php") { //When there are null values and php values in the array, change them back to false, that is, remove the ones in the array Empty values and php values
return false;
return
true; }
array
(
'A'
=>"Java", =>false, =>true,
'e'e = & gt; null,
'g' = & gt; 0,
'g1' = & gt; '0',
array_filter($input_array));
print_r(array_filter($input_array
,
"delEmpty")); The running result without callback function: can be seen , false, null, and true '' blanks and 0 are filtered out, and the subscript of the array has not changed.
There is the result of the callback function:
/**
* array_slice() function takes out a segment from the array
* array_slice(array array, int offset[, int length])
* According to the offset and length parameters specified A sequence in the array array.
* offset represents the starting position, length represents the length of this sequence.
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn