Home > Backend Development > PHP Tutorial > return 和echo的区别

return 和echo的区别

WBOY
Release: 2016-06-23 13:58:19
Original
951 people have browsed it

$key="永兴村到山水人家";$str="";		     $keys=explode('到',$key);             $json = @file_get_contents("http://api.map.baidu.com/direction/v1?mode=transit&origin=".$keys[0]."&destination=".$keys[1]."&region=北京&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;
Copy after login
这样子写为什么echo 可以,return不行


回复讨论(解决方案)

		public function huancheng($key)		{             $key="永兴村到山水人家";             $str="";		     $keys=explode('到',$key);             $json = @file_get_contents("http://api.map.baidu.com/direction/v1?mode=transit&origin=".$keys[0]."&destination=".$keys[1]."&region=舟山&output=json&ak=gfPnxaaiPyNIhM7c3eZ1kmEL");             $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;			 }			 $str=funv($v,$k);			 return $str;				         }
Copy after login

期待大神的出现。。。。

1楼是错的。。。。

大哥,你一楼是模式是:
代码行-------
代码行-------
函数---------
代码行------
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