I have something like this:
<?php
function send_pm(){
$text = "print this text on screen";
}
if(function_exists('send_pm')){
send_pm();
global $text;
echo $text;
}
?>
My intention, is to show the message within send_pm, using its own array, already defined on the function. As you see, if you actually execute this script, it will return nothing. I don't understand why this is happening, because I already defined the $text var.
Thank you guys.
Adjust your send_pm() function to:
function send_pm(){
global $text;
$text = "print this text on screen";
}
That said, I highly recommend against global variables as it isn't the best or safest way to do things.
If I correctly understood your requirements, you can try something like this instead:
function send_pm($msg_id) {
$messages = array(
'msg1' => 'print this text on screen',
'msg2' => 'print this other text on screen',
'msg3' => 'etc',
);
return $messages[$msg_id];
}
if (function_exists('send_pm')) {
echo send_pm('msg1');
}