Php 如何在数组中搜索匹配的文本

Php 如何在数组中搜索匹配的文本,php,arrays,Php,Arrays,我想知道是否有搜索数组的函数,其中第一个字母与所选字母匹配。我可以做一些不那么优雅的事情,比如 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. 你的问题不清楚。但下面我给出一个仅选择包含所需第一个字母的数组的选定元素的示例:

我想知道是否有搜索数组的函数,其中第一个字母与所选字母匹配。我可以做一些不那么优雅的事情,比如

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. 

你的问题不清楚。但下面我给出一个仅选择包含所需第一个字母的数组的选定元素的示例:

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;
}
结果:

Array
(
    [0] => Chops
    [1] => Club
) 

您可以发布您尝试的内容吗?您可以通过简单地更改
if
条件将此功能用于其他用途。
Array
(
    [0] => Chops
    [1] => Club
)