Source Code:
(back to article)
<?php $data = array("name" => "John Doe", "age" => 30); function display_data() { global $data; print_r($data); } class User { function show_data() { global $data; print_r($data); } } display_data(); // Array ( [name] => John Doe [age] => 30 ) $user = new User(); $user->show_data(); // Array ( [name] => John Doe [age] => 30 ) $GLOBALS['data']['email'] = "johndoe@example.com"; display_data(); // Array ( [name] => John Doe [age] => 30 [email] => johndoe@example.com ) $user->show_data(); // Array ( [name] => John Doe [age] => 30 [email] => johndoe@example.com ) ?>
Result:
Report an issue