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

WBOY
Release: 2016-06-23 13:27:42
Original
983 people have browsed it

不使用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;
Copy after login

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

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


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