开发者

Alphabetize results in view

开发者 https://www.devze.com 2023-01-13 07:11 出处:网络
开发者_运维技巧I\'m trying to do this in CodeIgniter. Here\'s my code I put into pastebin. As you can guess, it\'s not working. I need the view to render the results like this:

开发者_运维技巧I'm trying to do this in CodeIgniter. Here's my code I put into pastebin.

As you can guess, it's not working. I need the view to render the results like this:

  • A
  • A Client
  • A CLIENT 2
  • Another Client
  • B
  • Big Client
  • Brother client
  • C
  • Course I'm a Client
  • Coming Over Client


$prev_row = '';
foreach ($clients as $client) {
    $first_letter = strtoupper(substr($client['name'], 0, 1));
    if ($first_letter != $prev_row) {
        echo "<h3>$first_letter</h3>";
    }

    echo $client['name'] . "\n";
    $prev_row = $first_letter;
 }

Revised answer based on comments, not sure how your array is structured but this should point you in the right direction.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号