search

Home  >  Q&A  >  body text

Why is the number of the bottom layer of the hollow pyramid wrong?

$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~2432 days ago1155

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2018-06-18 21:44:12

    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
    0
  • Cassie~

    No, it's a character problem. I replaced the spaces inside with "p" and it worked.

    Cassie~ · 2018-06-19 22:32:08
  • Cancelreply