global variable
<?php $age = 25 function getAge(){ echo $age; } getAge(); /* Output will be error , because we have $age variable out of the function and it isn't global variable.If we want to function has output we need to add a global variable (global $age ) to the function */ ?> <?php //exapmle of global variable $age = 25 function getAge(){ global $age; echo $age; } getAge(); //output will be 25 ?>
by ana meskhi
2 years ago
PHP
php
global
variable
1
Pro tip: use ```triple backticks around text``` to write in code fences