PHP 8
Intermediate
Basics
· 1 min read
Local vs global scope
Why can’t my function see an outside variable?
global keyword / pass args.
Example
<?php
$site = 'CodePrimer';
function title() {
global $site;
return $site;
}
echo title();
Line-by-Line Walkthrough
Prefer passing parameters over global when possible.