/**
* Remove blank elements from the array (including elements with only blank characters)
*
* @param array $arr
* @param boolean $trim
*/
复制代码 代码如下:
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 of the conversion result will be an array containing all the data of the item.
*
* @param array $arr
* @param string $keyField
* @param string $valueField
*
* @return array
*/
复制代码 代码如下:
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;
}
http://www.bkjia.com/PHPjc/319294.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319294.htmlTechArticle/*** Remove blank elements from the array (including elements with only blank characters) * * @param array $arr * @param boolean $trim*/ 复制代码 代码如下: function array_remove_empty...