Do not use global variables, it is a bad design because it makes your code confusing and hard to read. There are much better alternatives.
Given your simple example, you can just return the value from the method:
function drop()
{
if(file_exists("test.php"))
{
$ddr="ok";
}
$test_end="ready";
return $test_end;
}
$test_end = drop();
If you have a more complicated case and for some reason cannot return the value, pass the variable by reference by prefixing with &
:
funtion drop(&$test_end)
{
if(file_exists("test.php"))
{
$ddr="ok";
}
$test_end="ready";
}
$test_end = null;
drop($test_end);
echo $test_end; // will now output "ready"
Passing by reference is also not a great pattern, because it still makes your code confusing.
More on why global variables are bad
The problem is if I'm looking at your code and all I see is this:
drop();
echo $test_end;
I have no idea how $test_end got set or what it's value is. Now let's say you have multiple method calls:
drop();
foo();
bar();
echo $test_end;
I now have to look at the definition of all these methods to find out what the value of $test_end is. This becomes a very big problem in larger code bases.