I have an array that already contains all it\'s values in alphabetical order:
Alligator
Alpha
Bear
Bees
Banana
Cat
Cougar
Now I just want to li
As Shivansh said above in his answer, I think that is correct way
$result = array();
foreach ($list as $item) {
$firstLetter = substr($item, 0, 1);
$result[$firstLetter][] = $item;
}
echo ""; print_r($result);
To Display the array generated by this code use
foreach ( $list as $key => $value ) {
//Do some thing with $key (A,B,C)
foreach ($value as $var){
//Do some thing with $var (Array of A, B ,C)
}
}