PHP代码求助= =打印实心菱形 为何这个代码无法运行,该怎样更改? 100
// put your code here
$line = 1;
while($line <= 9){
if($line <=5)
{
$empty_pod = $star_pos = 1;
$empty = 5 - $line;
$star = 2*$line - 1;
while($empty_pos <= $empty){
echo ' ';
++$empty;
}
while($star_pos <= $star){
echo '*';
++$star_pos;
}
}
else {
$empty_pod = $star_pos = 1;
$empty = $line - 5;
$star = 9 - 2*$empty;
while($empty_pos <= $empty){
echo ' ';
++$empty;
}
while($star_pos <= $star){
echo '*';
++$star_pos;
}
}
echo '<br>';
++$line;
}
?> 展开
打印实心菱形,就是四边形吧,我写一下我的逻辑,你参考下
function rum($value,$type=1){
$arr = '';
if(is_int($value)){
for($i=$value;$i>1;$i--){
if($type==1){
$arr .="*";
}else{
$arr .=" ";
}
}
}
return $arr;
}
$i=1;
while($i<=9){
$j=1;
echo rum($i,0)."*";
while($j<9){
if($i==1 || $i==9){
echo "*";
}else{
echo rum(8)."*";break;
}
$j++;
}
echo "<br>";
$i++;
}
谢谢,我想想