PWD || PHP : Membuat Piramida tengah kosong dengan PHP

Mujahid Habibullah
Sep 5, 2018 · 1 min read

Contoh output yang dimaskud dari judul tersebut adalah sebagai berikut :

untuk membuat aplikasi seperti gambar diatas membutuhkan kodingan seperti berikut :

<form action=” “ method=”GET”>
Jumlah Baris dan Kolom : <input type=”text” name=”n”><br>
<input type=”submit” name=”submit” value=”tampil”>
</form>

<?php
function baris ($n, $baris=1){
if ($baris <$n+1) {
kolom ($n,$baris);
echo “<br>”;
baris ($n,++$baris);
}
}
function kolom ($n,$baris,$kolom =1){
if ($baris == 1) {
if ($kolom ==$n) {
echo “*”;
}
else {
echo “&nbsp”;
}
}
else{
if ( ($kolom == ($n+1)- $baris) || ($kolom ==($n-1)+$baris)){
echo “*”;
}
else{
echo “&nbsp”;
}

}
if ($kolom<($n*2)) {
$kolom++;
kolom($n,$baris,$kolom);
}
}

if (isset($_GET [“submit”])) {
$n = $_GET [“n”];
baris($n);
}
?>

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade