2014-02-21 133 views

回答

4

如果不调用函数,什么都不会发生。

您需要echo $test;

1

不要使用global代替参数传递给你的函数。你也没有从你的函数返回值,也没有调用你的函数func_name

你一定在做这样的事情。

<?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 
0

可以像

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

甚至你可以尝试像

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

如果能够避免它永远不会使用全局变量添加func_name();。 –

+0

@RonniSkansing我did'nt – Gautam3164

+0

使用$这个课外不会工作 – MSadura