You can use the global keyword for this
function check_input($data)
{
global $spam;
if ( preg_match("/http/i", $data)) $spam = 'yes';
}
$data = "http://www.example.com";
check_input($data);
echo $spam;
echo $GLOBALS['spam'];
but the question is WHY would you want to do this, a much better approach would be to pass $spam is to the function by reference or return it as a return variable.
function check_input($data, &$spam)
{
if ( preg_match("/http/i", $data)) $spam = 'yes';
}
$data = "http://www.example.com";
$spam = "no";
check_input($data, $spam);
echo $spam;
echo $GLOBALS['spam'];
or
function check_input($data)
{
return ( preg_match("/http/i", $data))?'yes':'no';
}
$data = "http://www.example.com";
$spam = check_input($data);
echo $spam;
echo $GLOBALS['spam'];