Skip to content

Instantly share code, notes, and snippets.

@samelm
Created October 19, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samelm/1f1be229da57aa013692a3fd02b7ccec to your computer and use it in GitHub Desktop.
Save samelm/1f1be229da57aa013692a3fd02b7ccec to your computer and use it in GitHub Desktop.
Alphabet associative array
<?php
$result = [];
foreach ($array as $item) {
$letter = mb_strtoupper(mb_substr($item, 0, 1));
$result[$letter][] = $item;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment