The global Keyword
The global keyword is used to access a global variable from within a function.To do this, use the global keyword within the function, prior to the variables.
<?php
$name = 'David';
function getName() {
global $name;
echo $name;
}
getName();
//Outputs 'David'
?>
$name = 'David';
function getName() {
global $name;
echo $name;
}
getName();
//Outputs 'David'
?>
No comments:
Post a Comment