Functions in PHP
Functions in PHP
Code Example:
<?php
//basic example of a function. Just prints "Hello World" when called
function sayHello(){
echo "Hello World";
}
sayHello();
echo '<br />';
//function that uses a loop and condition to print some out put.
function printNumList(){
for($i=0; $i<=100; $i++){
if($i%2==0){
echo $i;
}
}
}
printNumList();
echo '<br />';
//function that takes an argument and returns a result.
function addFive($inputNum){
while($inputNum<=50){
$inputNum+=5;
}
return $inputNum;
}
echo addFive(15);
echo '<br />';
?>
Expected Output:
Hello World
02468101214161820222426283032343638404244464850525456586062646668707274767880828486889092949698100
55
The above is what you should see if you run the program in the browser.
Comments
Post a Comment