mercredi 1 novembre 2023

Converttng a pyramid patten python code to PHP

I have a python code that creates a right aligned pyramid pattern based on the number of rows specified. Kinda need help here on converting this to PHP, if that's even possible (im a baby beginner)

here's the code:

def pyramid(rows):
    for i in range(1, rows + 1):
        spaces = " " * (rows - i)
        stars = "*" * i
        print(spaces + stars)

pyramid(5)

ive tried manually converting it but the result in localhost doesnt look the same in the terminal in VSCode

here's the code:

<?php
function pyramid($rows) {
    for ($i = 1; $i <= $rows; $i++) {
        $spaces = str_repeat(" ", $rows - $i);
        $stars = str_repeat("*", $i);
        echo $spaces . $stars . "\n";
    }
}

pyramid(5);
?>

sorry in advance if ive made mistakes in asking this question, im new here

Aucun commentaire:

Enregistrer un commentaire