/**
* Remove blank elements from the array (including elements with only white spaces)
*
* @ Param array $ arr
* @ Param boolean $ trim
*/
Copy codeThe Code is as follows:
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 codeThe Code is as follows:
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;
}