Why is the number of the bottom layer of the hollow pyramid wrong?
Cassie~
Cassie~ 2018-06-17 01:50:08
0
2
1137

$n = 5;

//层数

for ($i=1; $i<=$n; $i ){

//空格

for ($k=1; $k<=$n-$i; $k ){

echo "  ";

}

//"*"号

for ($j=1; $j<=2*$i-1; $j ){

if ($i==1 || $i==$n){

echo "#";

}else{

if ($j==1 || $j==2*$i-1){

echo "#";

}else{

echo "  ";

}

}

}

echo "<br>";

}


Cassie~
Cassie~

reply all(1)
ringa_lee

Your logic is wrong

The ## logic below, just change it to this

//"*"号
for ($j=1; $j<=2*$i; $j++){
if ($i==$n){
 echo "#";
}else{
 if ($j==1 || $j==2*$i-1){    
echo "#";}else{   
 echo "&nbsp;&nbsp;";}
}}


  • reply No, it's a character problem. I replaced the spaces inside with "p" and it worked.
    Cassie~ author 2018-06-19 22:32:08
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template