首页 > 代码库 > for循环 打印菱形 空 和 实

for循环 打印菱形 空 和 实

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<?php
echo "实心菱形";
echo "<br/>";
for($q=1;$q<=5;$q++){
    for($t=1;$t<=5-$q;$t++){
        echo "&nbsp;";
    }
    for($k=1;$k<=2*$q-1;$k++){
        echo "*";
    }
    echo "<br/>";
}
for($q=1;$q<=4;$q++){
    for($t=1;$t<=$q;$t++){
        echo "&nbsp;";
    }
    for($k=1;$k<=8-2*$q;$k++){
        echo "*";
    }
    echo "<br/>";
}

echo "空心菱形";
echo "<br/>";
for($p=1;$p<=10;$p++){
    if($p<=5){
        for($b=1;$b<=5-$p;$b++){
            echo "&nbsp;";
        }
        for($c=1;$c<=2*$p-1;$c++){
            if($c==1||$c==2*$p-1){
                echo "*";
            }else{
                echo "&nbsp;";
            }
        }
        echo "<br/>";
    }
    else{
        for($b=0;$b<=$p-6;$b++){
            echo "&nbsp;";
        }
        for($c=1;$c<=7-2*($b-1);$c++){
            if($c==1||$c==7-2*($b-1)){
                echo "*";
            }else{
                echo "&nbsp;";
            }
        }
        echo "<br/>";
        $b++;
    }
}
?>