Delete the PHP array function that is used to delete array elements. Read the PHP array function that is used to delete array elements. delete blank elements (including elements with only blank characters) in php) convert a two-dimensional array to a hashmap. for details about the source of this article, refer to http://www.jb51.net/article/15522.htm?##*array ">
Php removes blank elements from an array (including elements with only blank characters) and converts a two-dimensional array to a hashmap
This article from: The foot home (www.jb51.net) detailed source reference: http://www.jb51.net/article/15522.htm
**
* Remove blank elements from the array (including elements with only white spaces)
*
* @ Param array $ arr
* @ Param boolean $ trim
*/
[Copy this CODE] CODE:
Function array_remove_empty (& $ arr, $ trim = true)
{
Foreach ($ arr as $ key => $ value ){
If (is_array ($ value )){
Array_remove_empty ($ arr [$ key]);
} Else {
$ Value = trim ($ value );
If ($ value = ''){
Unset ($ arr [$ key]);
} Elseif ($ trim ){
$ Arr [$ key] = $ value;
}
}
}
}
/**
* Convert a two-dimensional array to a hashmap
*
* If the $ valueField parameter is omitted, each item in the conversion result is an array containing all the data of the item.
*
* @ Param array $ arr
* @ Param string $ keyField
* @ Param string $ valueField
*
* @ Return array
*/
[Copy this CODE] CODE:
Function array_to_hashmap (& $ arr, $ keyField, $ valueField = null)
{
$ Ret = array ();
If ($ valueField ){
Foreach ($ arr as $ row ){
$ Ret [$ row [$ keyField] = $ row [$ valueField];
}
} Else {
Foreach ($ arr as $ row ){
$ Ret [$ row [$ keyField] = $ row;
}
}
Return $ ret;
}