Home  >  Article  >  Backend Development  >  有意思的PHP代码块-面试经典

有意思的PHP代码块-面试经典

WBOY
WBOYOriginal
2016-06-23 13:27:42993browse

不使用PHP自带反转函数,将字符串反转。

//不用自带函数将其反转方法一$str = "This is PHP";$strArr = explode(' ',$str);$count = count($strArr)-1;for($i=$count;$i>=0;$i--){	$revStr .= $strArr[$i].' ';}echo $revStr;方法二$str = "This is PHP";$strArr = explode(' ',$str);krsort($strArr);$res = implode($strArr,' ');echo $res;

    2. 获取客户端和服务端IP地址

客户端    方法一: echo $_SERVER['REMOTE_ADDR'];   方法二: getenv('REMOTE_ADDR');服务端    方法一: echo $_SERVER['SERVER_ADDR'];   方法二:getenv('SERVER_ADDR');


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