This may be a stupid question but I have some code like:
$userData = array_map('htmlentities', mysql_fetch_assoc(mysql_query(
"SELECT * FROM `smf_members`
WHERE `id_member` = (SELECT `id_member` FROM `smf_log_online` WHERE `session` = '" . mysql_real_escape_string($session) . "')"
)));
function printHeader()
{
$header = <<<eof
<!DOCTYPE html>
<html lang="en">
<head>
...
<li><a href="#"><img src="images/avatar.gif" alt="" /> {$userData['member_name']}</a>
...
eof;
echo $header;
}
That is in a file named config.php and is requireed in my index page like so:
<?php require 'config.php';printHeader(); ?>
However inside the printHeader() function $userData isn’t set, where as if I print_r($userData) in the global scope it is set. Do I need to put the rest of the “global” code in a constructor of sorts? Or am I missing something really small.
Thanks
Use the
globalkeyword.