string(3) "2_1" [2] => string(3) "2_2" [3] => string(3) "3_1" [4">
时间:2021-07-01 10:21:17 帮助过:15人阅读
$data =array("1_1","2_1","2_2","3_1","3_2","3_3");
$need="3_";
$ret = array_filter($data,function($item) use($need){
return strpos($item,$need) === 0;
});
var_dump($ret);
$d = array(
"1_1",
"2_1",
"2_2",
"3_1",
"3_2",
"3_3",
);
$in = '3_';
$out = array_values(
array_map(function($s) use (&$in) {
return substr($s, strlen($in));
}, preg_grep("/$in/", $d))
);
print_r($out);
Array
(
[0] => 1
[1] => 2
[2] => 3
)