Group by first letter, alphabetically, best way?

前端 未结 2 943
悲&欢浪女
悲&欢浪女 2021-01-21 12:41

Here is my code:

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 12:59

        $res      = array();
        while ($r = mysql_fetch_array($q)){
          $currentletter = substr($name,0,1);
          $res[$currentletter][]  = $name;
        }
    
        foreach($res as $key=>$val){
           /// here you add your li
           /// here $key will give you letter and $val will give you name
           echo $key;
           foreach($val as $reqvals){
              echo $reqvals;
              echo "
    "; } }

提交回复
热议问题