Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 处置多重数组

PHP 处置多重数组

WBOY
WBOYOriginal
2016-06-13 10:35:16830Durchsuche

PHP 处理多重数组


作者:林子木 wolinxuebin

博客地址:http://my.csdn.net/wolinxuebin

转载请保留

          今天在写PHP代码,要给手机端传送数据,数据是从mysql中取出来的。其中有个ID编号,mysql中存的是int型,取出来发现都成了string。

          在网上查了下,没有现成的解决方法,都仅仅说php是弱类型,没关系。可是,对方说,我要的是int型呀,没办法只能自己动手写了。

function array_intval(&$ar,$key,$base=10)	{	  foreach($ar as $k=>$v) {       		if(is_array($v)){    //判断是否是数组,一直将其打开    			 array_intval($ar[$k],$key,$base);  			}  			else {  				return $ar[$key] = intval($ar[$key],$base);  			}	  }	}
直接上代码。

array_intval($result, 'id');
调用直接这样写好了,因为传值进去是地址,所以不用再返回了。

其他处理也类似的,这可以说是一个模板。

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