搜索
首页php教程php手册通用返回特定格式的请求状态函数

返回状态码,消息,数据等内容特定格式的内容,它可以传1到5个参数,分别代表不同意义.
通用返回特定格式的请求状态函数$code = 'REGISTAR_FAILED';<br> $info = '-123';<br> $record = array(array('aaa','bbb'));<br> $count = 2;<br> $infovalue =  array(123456789,  '。当前时间:'.date('Y-m-d H:i:s'));<br> <br> print_r(back($code, $info, $record, $count, $infovalue));<br> print_r(back($code, $info, $record, $count));<br> print_r(back($code, $info, $record, $infovalue));//四个参数时, 第四个数组,就代表$infovalue<br> print_r(back(1,     $info, $record));//三个参数时,第一个为1(成功),第三个表示$record<br> print_r(back($code, $info, $infovalue));//三个参数时,不为1时(失败),第三个表示$infovalue<br> print_r(back($code, $info));<br> print_r(back($code));<br> <br> <br> <br> /**<br>  * 返回状态数据<br>  * @param string $code 状态符<br>  * @param string $info  消息内容/状态码<br>  * @param array $record 返回数据/变量参数<br>  * @param number $count 记录条数<br>  * @return array<br>  */<br> function back($code, $info=null, $record=null, $count=null, $infovalue=array()){<br>     <br>     $numargs = func_num_args();<br>     switch($numargs){<br>         case 2 : if(is_array($info)){$record = $info; $info = null;}<br>             break;<br>         case 3 : if($code != 1 && !empty($record)){$infovalue = $record; $record = null;}<br>             break;<br>         case 4 : if(is_array($count)){$infovalue = $count; $count = null;}<br>     }<br> <br>     $mincode = '';<br>     //消息内容为数字<br>     if(is_numeric($info)){<br>         $mincode = '('.$info.')'; $info = null;<br>     }<br>     <br>     if(empty($info)){<br>         //错误消息配置<br>         $STATUS_CODE = array('REGISTAR_FAILED' => '手机号码{0}不正确{1}' );<br>         $info = isset($STATUS_CODE[$code])? $STATUS_CODE[$code] : ($code == 1? 'success' : '未知错误');<br>     }<br>     <br>     $pattern  = '/\{(\w*)\}/';<br>     if(!empty($infovalue) && preg_match($pattern, $info)){<br>         $str = '';<br>         $str .= preg_replace_callback($pattern, function($matches){<br>             return '{$infovalue['.$matches[1].']}';<br>         }, $info);<br>         eval('$info="'.$str.'";');<br>     }<br> <br>     $return = array('status'=>$code, 'info'=>$info.$mincode, 'count'=>$count, 'data'=>$record);<br>     if($count == null) unset($return['count']);<br>     if($record == null) unset($return['data']);<br>     return $return;<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中