Adding PHP examples

This commit is contained in:
vendin
2017-09-21 00:00:43 +03:00
committed by Aditya Bhargava
parent 8ec4dc010b
commit 495a648a6a
9 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?php
function countdown($i)
{
echo $i;
// base case
if ($i <= 0) {
return;
} else {
countdown($i - 1);
}
}
countdown(5);

View File

@@ -0,0 +1,21 @@
<?php
function greet2($name)
{
echo 'how are you, ' . $name . '?';
}
function bye()
{
echo 'ok bye!';
}
function greet($name)
{
echo 'hello, ' . $name . '!';
greet2($name);
echo 'getting ready to say bye...';
bye();
}
greet('adit');

View File

@@ -0,0 +1,11 @@
<?php
function fact($x)
{
if ($x === 1) {
return 1;
}
return $x * fact($x - 1);
}
echo fact(5);