Reputation: 543
here is my question I have an Indexed array with n number of data I wanted to get data which starts from a particular letter.
array(
1 => 'Jim'
2 => 'Rao'
3 => 'Mathew'
4 => 'Raj'
...
)
eg: I need to get data starts from 'R'
any help will be really appreciated. Thanks!
Upvotes: 0
Views: 48
Reputation: 5727
foreach ($array as $value)
{
// we compare the first letter of every word in the array to R
if (substr($value, 0, 1) == "R")
{
// if the first letter is R, we put the value in a new array $result
$result[] = $value;
}
}
Upvotes: 1