Home > Backend Development > PHP Tutorial > 如何得到return 的值,

如何得到return 的值,

WBOY
Release: 2016-06-23 13:58:21
Original
1021 people have browsed it

		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;	         }
Copy after login

怎么把两个函数分开,然后可以得到$str的返回值。


回复讨论(解决方案)

        public function huancheng($key)        {             global $str;             $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');             return $str;            }         function funv($v, $k)          {           global $str;           if($k == 'stepInstruction')            {$str.= strip_tags($v);}          }
Copy after login
Copy after login
为什么要抱着 php 5.2 不放呢?

别岐视php5.2.
第一次见有人这样写东西
public function huancheng($key)
{

function funv($v, $k)
{

}
return $str;
}

代码看不懂。不好意思。

        public function huancheng($key)        {             global $str;             $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');             return $str;            }         function funv($v, $k)          {           global $str;           if($k == 'stepInstruction')            {$str.= strip_tags($v);}          }
Copy after login
Copy after login
为什么要抱着 php 5.2 不放呢?

主要bae上不支持啊,另外你这样写也报错的Warning: array_walk_recursive() [function.array-walk-recursive]: Unable to call funv()

如果 funv 是作为类的方法出现的,则应
array_walk_recursive($ar, array($this, 'funv'));

如果 funv 是作为类的方法出现的,则应
array_walk_recursive($ar, array($this, 'funv'));

老大,你太给力了!!!!
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