Home  >  Article  >  Backend Development  >  php怎么打印金字塔

php怎么打印金字塔

WBOY
WBOYOriginal
2016-06-13 13:00:211204browse

php如何打印金字塔

本帖最后由 xuzuning 于 2011-11-10 08:24:06 编辑
如何用php打印出空心金字塔 例如::*<br />
                                *   *<br />
                              * *  * *

------解决方案--------------------
<br />
<br />
<?php<br />
<br />
$sum = 30; //规模<br />
<br />
for ($i=0; $i<$sum/2; ++$i)<br />
{<br />
	echo '<p>';<br />
	for ($ii=0; $ii<$sum; $ii++)<br />
	{<br />
		$str = ($i < $sum / 2 - $ii) ? ' ': '*';<br />
		if($str == '*') $str = ($i == $sum / 2 - $ii <br><font color='#FF8000'>------解决方案--------------------</font><br> $ii == $sum / 2 + $i) ? '*': ' ';<br />
		if($i+1 == $sum/2 && $ii != 0) $str = '*'; <br />
		echo $str;<br />
	}<br />
	echo '</p>';<br />
}<br />
?><br />
<br />



看看。。=_=.. 可以优化就优化下吧。。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn