输入一个奇数,用递归方法输出对应的菱形

function printRhombus($n){ if($n == 1){ echo '*'; }elseif($n%2 == 1){ $ret = printOne($n,1); $newstr = strrev($ret); $newstr = substr($newstr,$n); $strrhombus .= $ret.$newstr; echo $strrhombus; }else{ echo "请输入奇数"; } } function printOne($n,$m){ if($n == $m){ $retstr .= str_repeat("*",$m); }elseif($n>$m){ $blanklen = ($n-$m)/2; $retstr .= str_repeat(" ",$blanklen); $retstr .= str_repeat("*",$m); $retstr .= str_repeat(" ",$blanklen); $m = $m + 2; $retstr .= printOne($n,$m); } return $retstr; } printRhombus(7);

回答坛子里面的问题

你可能感兴趣的:(function)