Home  >  Article  >  php教程  >  php函数:实现从二维数组对象返回一维数组

php函数:实现从二维数组对象返回一维数组

WBOY
WBOYOriginal
2016-06-13 10:38:421211browse

function getOneDimArray($arr,$value,$key="id"){
        $array = array();
        if(is_array($arr) && !empty($arr)){
                foreach($arr as $k=>$val){
                        $array[$val->$key] = $val->$value;
                }
                return $array;
        }else return $arr;
}


?>

  • 来源: 编程之家
  • Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn