php 中定义常量和一个数组

PHP  

<?php
class myclass
{

	//状态:取消
	const STATUS_ABORT = -1;
	//状态:签约
	const STATUS_SIGN = 0;
	//状态:执行
	const STATUS_ATTEND = 1;
        //定义一个返回数组的函数
	public static function statusArray(){
		return array(
			self::STATUS_ABORT => '取消', 
			self::STATUS_SIGN => '签约', 
			self::STATUS_ATTEND => '执行',
		);
	}

	//根据状态码转文字
	public static function statusDecode($status_num){
		$reval = '';
		$t = self::statusArray();
		return $t[(string)(intval($status_num) ? intval($status_num) : self::STATUS_ABORT)];
	}

}

echo myclass::statusDecode(-1);


?>

运行结果是:取消


记录一下今天学习的内容。

时间:2017年03月19日    作者:孟德    分类:后端   浏览:2028    评论:0

链接地址:https://www.abclogs.com/backend_php_const_array.html

评论列表

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。