Alphabetize results in view
开发者_运维技巧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.
精彩评论