代码
public function heightlist(){
$result = HeightModel::select('height') ->orderBy('height') ->get();
$buxianlist = self::hebingArray($result,'height','cm');
$list['不限'] = $buxianlist;
foreach($result as $key => $val){
$re = HeightModel::whereBetween('height', [$val['height'], 212])
->select('height') ->orderBy('height') ->get();
$buxianlist = self::hebingArray($re,'height','cm');
$list[$val['height'].'cm'] = $buxianlist;
}
return $this ->apijson('ok','成功',$list );
}
public function hebingArray($result,$label,$unit){
$buxian[] = array(array($label=>'不限'));
$buxian[] = $result;
foreach($buxian as $buxiankey => $buxianval){
foreach($buxianval as $buxiank => $buxianv){
if($buxianv[$label] != "不限"){
$buxianlist[] = $buxianv[$label].$unit;
}else{
$buxianlist[] = $buxianv[$label];
}
}
}
return $buxianlist;
}
格式样式例如: