How To Implement PHP Code To Display Alphabet Triangle

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

Using PHP we can print alphabets in a triangle shape or in a pyramid form. using range() with for loop and chr() with for loop.So today we discuss how to do it.

How To Implement PHP Code To Display Alphabet Triangle

Complete Code For Implementing PHP Code To Display Alphabet Triangle.
 

<!DOCTYPE html>
<html>
<head>
    <title>How To Implement PHP Code To Display Alphabet Triangle</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;">Implement PHP Code To Display Alphabet Triangle</h1>
    </div>

    <div class="well">

        <?php
            echo 'Using Range Function <br>';
        $alpha = range('A', 'Z');
        for($i=0; $i<5; $i++){
            for($j=5; $j>$i; $j--){
                echo $alpha[$i];
            }
            echo "<br>";
        }
        echo 'Using Char Function <br>';
        for( $i=65; $i<=69; $i++){ // ASCII value
            for($j=5; $j>=$i-64; $j--){
                echo chr($i);
            }
            echo "<br>";
        }

        ?>
    </div>
</div>
</body>
</html>

Related Post