PHP print triangle diamond

3.74K views
no comments
11 Aug 2016 1:19 am

This is easy and too much loop less code to write diamond and triangle shapes

Following code is diamond with the technique of css inline styles

echo '<p style="text-align:center;font-family: Verdana;line-height: 5px;">';
for($I=0;$I<=5;$I++){
	echo str_repeat('*',$I);
	echo '<br />';
}

for($D=6;$D>=1;$D--){
	echo str_repeat('*',$D);
	echo '<br />';
}

echo '</p>';

Result of diamond code

*
**
***
****
*****
******
*****
****
***
**
*

Following code is normal triangle with the technique of css inline styles

echo '<p style="text-align:left;font-family: Verdana;line-height: 5px;">';
for($I=0;$I<=5;$I++){
	echo str_repeat('*',$I);
	echo '<br />';
}

for($D=6;$D>=1;$D--){
	echo str_repeat('*',$D);
	echo '<br />';
}

echo '</p>';

Result of triangle code

*
**
***
****
*****
******
*****
****
***
**
*

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>