<?php
/*
*
**
***
****
*****
*/
for($line=1; $line<=5; ++$line){
for($pos=1; $pos<=$line; ++$pos){
echo '*';
}
echo '<br>';
}
/*
*
***
*****
*******
*********
*/
echo '<hr>';
for($line=1; $line<=5; ++$line){
for($pos=1, $max=2*$line-1; $pos<=$max; ++$pos){
echo '*';
}
echo '<br>';
}
/*
*
***
*****
*******
*********
*/
echo '<hr>';
for($line=1; $line<=5; ++$line){
for($pos=1, $max=5-$line; $pos<=$max; ++$pos){
echo ' ';
}
for($pos=1, $max=2*$line-1; $pos<=$max; ++$pos){
echo '*';
}
echo '<br>';
}
/*
*
* *
* *
* *
* *
*/
echo '<hr>';
for($line=1; $line<=5; ++$line){
for($pos=1, $max=5-$line; $pos<=$max; ++$pos){
echo ' ';
}
for($pos=1, $max=2*$line-1; $pos<=$max; ++$pos){
if($pos==1 || $pos==$max){
echo '*';
}else{
echo ' ';
}
}
echo '<br>';
}
/*
*
* *
* *
* *
*********
*/
echo '
打印星星*** php
最新推荐文章于 2023-10-24 18:05:43 发布
这段PHP代码展示了如何利用循环结构生成不同类型的星形图案,包括简单的星号递增排列,倒置的星形,以及更复杂的空格和星号组合形成的图形。

最低0.47元/天 解锁文章
502





