Files
freeCodeCamp/guide/english/php/functions/index.md
2019-02-19 10:40:21 -08:00

982 B

title
title
Functions

PHP Functions Introduction

A function is a block of statements that can be used repeatedly in a program.

Simple Function + Call

function say_hello() {
  return "Hello!";
}

echo say_hello();

Simple Function + Parameter + Call

function say_hello($friend) {
  return "Hello " . $friend . "!";
}

echo say_hello('Tommy');

strtoupper - Makes all Chars BIGGER AND BIGGER!

function makeItBIG($a_lot_of_names) {
  foreach($a_lot_of_names as $the_simpsons) {
    $BIG[] = strtoupper($the_simpsons);
  }
  return $BIG;
}

$a_lot_of_names = ['Homer', 'Marge', 'Bart', 'Maggy', 'Lisa'];
var_dump(makeItBIG($a_lot_of_names));

strtolower Function

The strtolower() function converts a string to lowercase.

<?php
  echo strtolower("Hello WORLD."); //hello world.
?>

More Information: