Learning PHP and MySQL
Example 03-07 The default handling of variable scope
<?php
// define a function function birthday(){
// Set age to 1
$age = 1;
}
// Set age to 30
$age = 30;
// Call the function
birthday();
// Display the age echo $age;
?>
Displays:
30
I can’t believe that this:
<?php
// define a function function birthday(){
// Set age to 1
$age = 1;
}
// Set age to 30
$age = 30;
// Call the function
birthday();
// Display the age echo $age;
?>would actually achieve any useful result. Maybe you meant
<?php
// define a function
function birthday(){
// Set age to 1
$age = 1;
}
// Set age to 30
$age = 30;
// Call the function
birthday();
// Display the age
echo $age;
?>Seeing things like this on your web site makes me wish that I hadn’t ordered this book from Amazon - maybe it’s not too late to cancel my order. Gotta go now.
Posted by Rex Robards on 10/12 at 07:55 PM