Skip to content

Instantly share code, notes, and snippets.

@cladjidane
Created May 2, 2023 13:42
Show Gist options
  • Save cladjidane/68cfbe28e650f71db0b5c1ad6207828e to your computer and use it in GitHub Desktop.
Save cladjidane/68cfbe28e650f71db0b5c1ad6207828e to your computer and use it in GitHub Desktop.
<?php
/**
* \\Author: Thibault Napoléon "Imothep"
* \\Company: ISEN Yncréa Ouest
* \\Email: [email protected]
* \\Created Date: 05-Apr-2023 - 12:25:38
* \\Last Modified: 13-Apr-2023 - 10:36:33
*/
//----------------------------------------------------------------------------
//--- drawTriangle -----------------------------------------------------------
//----------------------------------------------------------------------------
// Draw a triangle with a size, a filling character and the filling state.
// \param size The size of the triangle.
// \param character The filling character.
// \param isFilled True if the triangle is filled, false otherwise.
function drawTriangle($size = 10, $character = "*", $isFilled = false)
{
echo '<pre>';
for ($i = 1; $i <= $size; $i++)
{
for ($j = 1; $j <= $i; $j++)
{
if (!$isFilled && $j != 1 && $j != $i && $i != $size)
echo " ";
else
echo "$character ";
}
echo "\n";
}
echo '</pre>';
}
// Function test.
// drawTriangle(10, '.', false);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment