返回状态码,消息,数据等内容特定格式的内容,它可以传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元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)
