Home >Backend Development >PHP Tutorial >PHP function: Return a one-dimensional array from a two-dimensional array object_PHP tutorial
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;
}
?>