我需要在数组中的每个辅音之后放一个a
,例如:
hello
结果将是:haelalao
答案 0 :(得分:2)
答案 1 :(得分:1)
foreach
但是,内部循环适用..
$str="hello";
$srch=array_diff(str_split($str),array('a','e','i','o','u'));
echo str_replace('aa','a',str_replace($srch,array_map(function ($v){ return $v.'a';},$srch),$str));
<强> OUTPUT:
强>
haelalao
答案 2 :(得分:0)
<?php
$str = 'hello';
$vowels = array('a', 'e', 'i', 'o', 'u');
$new = str_split($str);
$converted = '';
foreach ($new as $each) {
if(in_array($each, $vowels)) {
$converted .= $each;
} else {
$converted .= $each.'a';
}
}
?>
答案 3 :(得分:0)
function ConvertString($convert) {
return preg_replace('/[b-df-hj-np-tv-z]/i', '${0}a', '$convert');
}
echo ConvertString("Hello");