This is done using the global keyword. Here is an example
<?php
$data = "Nothing to declare";
function nothing() { echo @"I have $data"; }
function todeclare() { global $data; echo "I have $data"; }
nothing(); echo "<br />"; todeclare();
?>
This will print on the first line:
'I have'
and then on the next line
'I have Nothing to declare'
This illustrates that the global keyword is needed to allow the function to access its value from outside the function.