mardi 25 mai 2021

Star pattern in php

<html>
    <body>
    <form action="" method="post">
    input:<input type="number" name="number">
    </form>
    <?php
    for ($row = 1; $row <= $_POST["number"]; $row++)
    {
    for ($col = 1; $col <= ($row >= ($_POST["number"]/2) ? ($_POST["number"]+1)- $row : $row); $col++)
        {
            echo '* ';
        }
    
         echo "<br>";
    `enter code here`
    print(json_encode(count($row)));
    
    ?>
 

if i give the input 12,13 and so on i am not able to get correct output.

current output:

current output

expected Output:

expected output

and i want to get the total number of stars count for each row.

Aucun commentaire:

Enregistrer un commentaire