gistfile1.txt // +----------------------------------------------------------------------// |获取二维数组中指定的一列,PHP5.5以后有专用函数array_column()// +----------------------------------------------------------------
// +---------------------------------------------------------------------- // |获取二维数组中指定的一列,PHP5.5以后有专用函数array_column() // +---------------------------------------------------------------------- // |@param array $arr // +---------------------------------------------------------------------- // |@param string $col // +---------------------------------------------------------------------- // |@param string $col_key // +---------------------------------------------------------------------- // |@return array // +---------------------------------------------------------------------- if (!function_exists('array_column')) { function array_column($arr, $col, $col_key = '') { $name_list = array(); if ($col_key) { array_map(function ($value) use (&$name_list, $col, $col_key) { $name_list[$value[$col_key]] = $value[$col]; }, $arr); } else { array_map(function ($value) use (&$name_list, $col) { $name_list[] = $value[$col]; }, $arr); } return $name_list; } }