Heim  >  Artikel  >  Backend-Entwicklung  >  php中调用其他文件中的函数解决办法

php中调用其他文件中的函数解决办法

WBOY
WBOYOriginal
2016-06-13 10:16:361547Durchsuche

php中调用其他文件中的函数
例如:我在common.php中写了一个函数

function get_provide_name($provide, &$pname)
{
if($provide == 0)
{
$pname = "中国移动";
}
else if($provide == 1)
{
$pname = "中国联通";
}
else if($provide == 2)
{
$pname = "中国电信";
}
else
{
$pname = "未知";
}
}

我在a.php中调用这个函数:
get_provide_name($provide, $pname);

如下使用:

'.$pname.'

总是显示方框。是为什么。
我现在只能把这些公共函数拷贝到 a.php中才会正常。



------解决方案--------------------
显示方框???查一下两个文件的编码
------解决方案--------------------
方框如一万米答案

其他建议
第一个 函数使用返回值不要使用&$

第二个 用switch 来控制吧 别这么 if if if 了...

$provide=intval($provide);
switch($provide):
case 0:
return "中国移动";
break;
case 1:
xxxx
break;
...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn