/*
Array_filter () filters cells in an array with a callback function
Array_filter (array,function)
Parameter description: If the custom filter function returns True, the current value of the array being manipulated is included in the returned result array.
And make a new array of results, if the original array is an associative array, the key name remains unchanged.
*/
function Delempty ($val) {
if ($val = = = "" | | $val = = = "php") {//when null and PHP values are present in the array, return false, that is, remove null values and PHP values from the array
return false;
}
return true;
}
$input _array = Array (' A ' = = ' Java ',
' B ' =>false,
' B1 ' =>true,
' C ' and ' = ',
' D ' and ' = ',
' E ' =>null,
' G ' =>0,
' G1 ' = ' 0 ',
' H ' = ' php ');
Print_r (Array_filter ($input _array));
Print_r (Array_filter ($input _array, "Delempty"));
?>
The result of running without a callback function:
As you can see, false,null, and the real ' blank ' and 0 are filtered, and the subscript of the array has not changed.
There is a result of the callback function running:
[PHP] view plaincopyprint?
/**
* the Array_slice () function takes a paragraph out of the array
* Array_slice (array array, int offset[, int length])
* A sequence of arrays in an array, as specified by the offset and length parameters.
* Offset indicates the start position, and length indicates how long the sequence is.
* True key does not change
*/
$input = Array ("Java", "Php",
"C + +", "C #",
"Ruby", "object-c");
$outputA = Array_slice ($input, 2); Returns "C + +", "C #", "Ruby", "Object-c"
$outputB = Array_slice ($input,-2, 1); Returns "Ruby"
$outputC = Array_slice ($input, 1, 3); Returns "PHP", "C + +", "C #"
Print_r ($outputA);
Print_r ($outputB);
Print_r ($outputC);
Print_r (Array_slice ($input, 2,-1, true));
Print_r (Array_slice ($input, 2,-1));
?>
Operation Result: