Group PHP results on first letter of name

后端 未结 6 1399
粉色の甜心
粉色の甜心 2020-12-10 17:25

I have a query which gets all records ordered by last_name. Now I would like to create a loop that groups these results by the first letter of the last name and display the

6条回答
  •  攒了一身酷
    2020-12-10 17:51

    Allready tried something like this?

    $last = '';
    foreach($data as $key=>$row){
        if(substr($row['last_name'],0,1)!=$last) echo '

    '.substr($row['last_name'],0,1).'
    ----------------
    '; $last = substr($row['last_name'],0,1); echo $row['last_name']; }

提交回复
热议问题