this is probably a basic question about php, but I can't figure out how to solve it.
Well, I have a file called globals.php
<?php
$DATA = array(
'first' => 'LOL',
'second' => 'Whatever'
);
?>
And I also have another file (omg.php) with the following function:
<?php
require_once('globals.php');
function print_text_omg($selector = 0){
global $DATA; //added this line of code. NOW IT WORKS
$var = '';
if($selector == 0){
$var = '';
}else{
$var = 'Hi. ';
}
//$DATA is a variable from globals.php that is supposed to be declared in require_once('globals.php');
//$var is a variable inside the function print_text_omg
//I am trying to concatenate string $var with the string $DATA['first']
$finaltext = $var.$DATA['first'];
echo $finaltext;
}
?>
Then, in main.php I have this:
<?php
include('omg.php');
print_text_omg();
print_text_omg(1);
?>
This should print something like:
//LOL
//Hi. LOL
Instead, I have this warning:
Notice: Undefined variable: DATA in ...
Which is the part of $finaltext = $var.$DATA['first'];
UPDATE
Thanks to user Casimir et Hippolyte' suggestion, I've edited my function and it works now. Added the line that worked for me.