Delete array elements Practical PHP array functions php delete blank elements from the array (including elements with only white spaces) convert a two-dimensional array to hashmap this article is from: Feet home (www.jb51.net) for details, refer to: www.jb51.netarticle15522.htm *** to delete blank elements from the array (including elements with only blank characters) ** @ paramarray to delete an array element Practical PHP array function
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;
}