public static function getAbcSortArr($paramArr) { $options = array('data' => ''); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); if (!is_array($data)) { $data = explode(',', $data); } $classArr = array(); if ($data) { foreach ($data as $key => $value) { //进行字母索引 $f_letter = API_Item_Base_String::getFirstLetter(array('input' => $value)); $akey = ord($f_letter); $classArr[$key] = array("val" => $value, "letter" => $f_letter); } } return $classArr; }
/** * 产品线选择 */ public function doSelectSubcate(ZOL_Request $input, ZOL_Response $output) { $manuId = (int) $input->get('manuId'); $subcateIdStr = $input->get('subcateIdStr'); if ($subcateIdStr) { $subcateIdArr = explode(',', $subcateIdStr); } #取得所有品牌数据 // $dataArr = ZOL_Api::run("Pro.Cate.getSubcateByDb" , array( // 'manuId' => $manuId, #品牌ID // 'noSecond'=> 1 // )); #数据源数组配置 $dataArr = Helper_Pro_Pro::getSubcateTemp(array()); if ($dataArr) { foreach ($dataArr as $key => $val) { if (isset($subcateIdArr) && in_array($val['subcateId'], $subcateIdArr)) { continue; } $manuName = ZOL_String::trimWhitespace($val['name']); #获得首字母 $tfl = API_Item_Base_String::getFirstLetter(array('input' => $manuName)); if (!isset($outArr[$tfl])) { $outArr[$tfl] = array('name' => $tfl, 'cons' => array()); } $outArr[$tfl]['cons'][] = $val; } sort($outArr); $output->outArr = $outArr; } $output->setTemplate('Ajax/SelectSubcate'); }
/** * 将数组装换的首字母分装的数组 */ public static function transFirstLetterArr($paramArr) { $options = array('data' => array(), 'type' => 1, 'sel' => false); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); $outArr = array(); if ($data) { if ($type == 1) { #1:默认select 形式 return api_json_encode($data); } elseif ($type == 3) { #原生态select的option $out = ''; foreach ($data as $k => $wd) { $seled = $sel == $k ? "selected" : ""; $out .= "<option value='{$k}' {$seled}>{$wd}</option>"; } return mb_convert_encoding($out, "UTF-8", "GBK"); } elseif ($type == 2) { #div select 形式 foreach ($data as $k => $wd) { $l = API_Item_Base_String::getFirstLetter(array('input' => $wd)); #获得首字母 if (!isset($outArr[$l])) { $outArr[$l] = array('name' => $l, 'cons' => array()); } $outArr[$l]['cons'][] = $wd; } //var_dump($outArr); sort($outArr); return api_json_encode($outArr); } elseif ($type == 4) { #原生态select,按照字母排序的 foreach ($data as $k => $wd) { $l = API_Item_Base_String::getFirstLetter(array('input' => $wd)); #获得首字母 $outArr[$k] = $l . "_" . $wd; } asort($outArr); $out = ''; foreach ($outArr as $k => $wd) { $seled = $sel == $k ? "selected" : ""; $out .= "<option value='{$k}' {$seled}>{$wd}</option>"; } return $out; } } return ''; }