php怎么打印金字塔

WBOY
Release: 2016-06-13 13:00:21
Original
1203 people have browsed it

php如何打印金字塔

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

------解决方案--------------------
<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 />
Copy after login



看看。。=_=.. 可以优化就优化下吧。。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template