PHP Program to print Right angled triangle of Stars

You could have seen a lot of programs in C language to print patterns. But a very few blogs / websites teaching how to print patterns in PHP. One of the blog is ours of-course.

In this blog, i am going to teach you how to print a right angled triangle in PHP.

Like this,

right-angled-traingle

<?php
 
if($_GET){
 
	$n = $i = $_GET['stars'];
 
	while ($i--){
		echo str_repeat('*', $n - $i)."<br>";
	}
}
?>
<html>
	<head></head>
	<body>
		<form>
			Enter number of lines: <input type="text" name="stars" />
		</form>
	</body>
</html>

You can see the demo here,

demo

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top