Home  >  Article  >  Backend Development  >  return 跟echo的区别

return 跟echo的区别

WBOY
WBOYOriginal
2016-06-13 11:55:251161browse

return 和echo的区别

$key="永兴村到山水人家";
$str="";
$keys=explode('到',$key);
$json = @file_get_contents("http://api.map.baidu.com/direction/v1?mode=transit&origin=".$keys[0]."&destination=".$keys[1]."®ion=北京&output=json&ak=gfPnxaaiPyNIhM7c13eZ1kmEL");
$ar = json_decode($json,true);
array_walk_recursive($ar, 'funv');
function funv($v, $k)
{
global $str;
if($k == 'stepInstruction')
{$str.= strip_tags($v);}

}
return $str;
这样子写为什么echo 可以,return不行
------解决方案--------------------
大哥,你一楼是模式是:
代码行-------
代码行-------
函数---------
代码行------
return 的模式
当然不行啦,return不在函数里啊。

你二楼的模式是:函数里面套函数的模式;要不你用类的方式去写,要不就把两个函数单独开,不要嵌套,在主函数里面return 。
------解决方案--------------------
function funv($v, $k) 
             {
        ...
                return $str;
             }
             

return返回值,
echo 显示值

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn