This article mainly shares with you how to print hollow diamonds in PHP, mainly in the form of code. I hope it can help you.
<?php function star($num) { if($num>0) { for($i=0; $i<$num; $i++) { //左上 if($i<1) { for($j=0; $j<($num-$i-1); $j++) { echo " "; } echo "*<br/><br/>"; } else { for($j=0; $j<($num-$i-1); $j++) { echo " "; } echo "*"; //右上 for($j=0; $j<(2*$i-1); $j++) { echo " "; } echo "*<br/><br/>"; } } for($i=1; $i<$num; $i++) { //左下 if($i>0) { for($j=0; $j<$i; $j++) { echo " "; } echo "*"; } //右下 if($i>0 && $i<($num-1)) { for($j=0; $j<2*($num-$i)-3; $j++) { echo " "; } echo "*<br/><br/>"; } } } } star(3); ?>
Related recommendations:
php output hollow diamond php7 php environment construction php from entry to proficiency
The above is the detailed content of PHP realizes printing hollow diamond. For more information, please follow other related articles on the PHP Chinese website!