PHP: Passing arguments to functions

The input values supplied to a function are called arguments.

We can modify page_header( ) to take an argument that holds the page color.

<?php

function page_header($color)
{
    print '<html><head><title>Welcome to my site</title></head>';
    print '<body bgcolor="#' . $color . '">';
}

$color = '#E3DCDC';
page_header($color);
$user = 'Daryl';
print "Welcome, $user";
page_footer();

function page_footer()
{
    print '<hr>Thanks for visiting.';
    print '</body></html>';
}

 

Series Navigation<< PHP: Declaring functions
PHP: Built-in functions >>
Posted in