was wondering if there's a function to search an array, where the first letter matches a letter chosen. I could do something less elegant like
Loop through array
Each item remove the first character, match to chosen search variable e.g if the first letter from apple, a equals my selection a, show.
Your question is not clear. But below I give you an example of selecting only the selected elements of an array that contain the first letter you want:
function select_from_array($first_letter,$array){
$return = Array();
for($i=0;$i<count($array);$i++){
if($array[$i][0] === $first_letter) $return[] = $array[$i];
}
return $return;
}
Example:
$arr = Array("Nice","Chops","Plot","Club");
print_r(select_from_array('C',$arr));
Result:
Array
(
[0] => Chops
[1] => Club
)