<?php
function set_name($name) {
$GLOBALS['name'] = $name;
}
function get_name() {
return $GLOBALS['name'];
/* Above line is equal to:
* global $name;
* return $name;
*/
}
function wrap($txt) {
echo 'Your username is ' . get_name() . ' ' . $txt;
}
/* You should not print/echo stuff in a function. So the better way would be:
* function wrap($txt) {
* return 'Your username is ' . get_name() . $txt;
* }
* echo wrap($txt)
*/
// Usage:
set_name('Rajitha');
wrap('tobacco');