I have an array with terms and definitions:
$myArray = array("apple" => "Fruit that grows ...", "car" => "Vehicle on four...");
How do I determine if I have words starting with a particular letter in $myArray, say, “c” for car and add a class to corresponding letter in my ABC list that is generated via a loop:
foreach(range('A','Z') as $i) {
echo '<div>'. $i .'</div>';
}
UPDATE:
Expected output:
<div class="match">A</div>
<div>B</div>
<div class="match">C</div>
You need to compare whether the character you are about to output does exist as a first character in the array keys. Compared with all the other working solutions, which iterate over the whole data array over and over again, using a little preparation should make it easier and more understandable what happens.
Output: