在功能WiTHOUT之外使用函数变量调用函数[关闭]

I have a need for this. Is it possible?

I tried the following but it doesn't work:

$test;

function func_name() {
    global $test;
    $test = 'string';
}

echo $test; // I get nothing

If you don't call the function, nothing will happen.

You need to add func_name(); before echo $test;

Don't use global instead pass arguments to your function. Also you are not returning the value from your function nor calling your function func_name.

You must be doing something like this.

<?php

function func_name() {   //<---- Removed the global keyword as it is a bad practice
    $test = 'string';
    return $test;   //<---- Added a retuen keyword
}
$test=func_name(); //<---- Calls your function and the value is returned here
echo $test; //"prints" string

Can do like

function func_name() {
    $test = 'string';
    return $test;
} 
echo func_name();

Or even you can try like

function func_name() {
    $test = 'string';
    echo $test;
} 
func_name();