return 跟echo的区别

WBOY
Release: 2016-06-13 11:55:25
Original
1261 people have browsed it

return 和echo的区别

$key="永兴村到山水人家";<br />$str="";<br />		     $keys=explode('到',$key);<br />             $json = @file_get_contents("http://api.map.baidu.com/direction/v1?mode=transit&origin=".$keys[0]."&destination=".$keys[1]."&region=北京&output=json&ak=gfPnxaaiPyNIhM7c13eZ1kmEL");<br />             $ar = json_decode($json,true);<br />             array_walk_recursive($ar, 'funv');<br />             function funv($v, $k) <br />			 {<br />			   global $str;<br />               if($k == 'stepInstruction') <br />			   {$str.= strip_tags($v);} <br />			   <br />			 }<br />			 return $str;
Copy after login
这样子写为什么echo 可以,return不行
------解决方案--------------------
大哥,你一楼是模式是:
代码行-------
代码行-------
函数---------
代码行------
return 的模式
当然不行啦,return不在函数里啊。

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

return返回值,
echo 显示值

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!