$str = 'RM,RMVB,MKV,MP4,MPEG,MPG,DAT,flv,m3u8,wmv,avi,3gp,amv,dmv'; //转换为小写 $str = strtolower($str); $ary = explode(',',$str); //回调函数 修改每个值元素 print_r(array_reduce($ary,'myfunction','')); function myfunction($v1,$v2) { return $v1 . "'" . $v2."',"; } exit();
也可以用map很方便
$str = 'RM,$str); print_r(array_map("myfunction",$ary)); function myfunction($v1) { return "*." . $v1."; "; } exit;原文链接:https://www.f2er.com/javaschema/285885.html