这是我的代码:
$sc = 'hello 8491241 some text 6254841 some text 568241 414844:412';
preg_match_all('/[0-9]{5,10}/', $sc, $matches1);
preg_match_all('/[0-9]{5,10}:[0-9]{1,5}/', $sc, $matches2);
function cub1($match)
{
return array(
'batch' => $match,
'type' => '1',
);
}
function cub2($match)
{
return array(
'batch' => $match,
'type' => '2',
);
}
$pr_matches1 = array_map('cub1', $matches1[0]);
$pr_matches2 = array_map('cub2', $matches2[0]);
$all_matches = array_merge($pr_matches1,$pr_matches2);
它工作正常,我在问是否可以改进我的代码并将array_map回调函数(cub1和cub2)作为一个函数(cub),我只需要为$matches1和$matches2设置不同的“类型”
请问有什么想法吗?