Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP foreach-从多维数组搜索匹配_Php_Search_Multidimensional Array_Foreach_Match - Fatal编程技术网

PHP foreach-从多维数组搜索匹配

PHP foreach-从多维数组搜索匹配,php,search,multidimensional-array,foreach,match,Php,Search,Multidimensional Array,Foreach,Match,我有一个数组 $Cat[0]['name'] = "garfield 1"; $Cat[0]['color'] = "brown"; $Cat[0]['weight'] = "15"; $Cat[0]['age'] = "3"; $Cat[1]['name'] = "garfield 2"; $Cat[1]['color'] = "brown"; $Cat[1]['weight'] = "15"; $Cat[1]['age']

我有一个数组

    $Cat[0]['name']     = "garfield 1";
$Cat[0]['color']    = "brown";
$Cat[0]['weight']   = "15";
$Cat[0]['age']      = "3";

    $Cat[1]['name']     = "garfield 2";
$Cat[1]['color']    = "brown";
$Cat[1]['weight']   = "15";
$Cat[1]['age']      = "3";
搜索词“gar”应返回两种猫的数据。 搜索单词“加菲猫1”,只返回cat[0]的数据

编辑

$garCats = array_filter($Cat, function($catDetails) { 
                                  return (strpos($catDetails['name'],'gar') !== FALSE); 
                              } 
                       );
$searchString = 'gar';
$garCats = array_filter($Cat, function($catDetails) use($searchString) { 
                                  return (strpos($catDetails['name'],$searchString) !== FALSE); 
                              } 
                       );