一般写法: foreach($result as $key=>$info){ switch($info['status']){ case self::STATUS_DELETED: $result[$key]['status_name'] = '已删除'; $result[$key]['action_act'] = ''; break; case self::STATUS_DRAFT: $result[$key]['status_name'] = '草稿'; $result[$key]['action_act'] = '上线'; break; case self::STATUS_ONLINE: $result[$key]['status_name'] = '已上线'; $result[$key]['action_act'] = '下线'; break; case self::STATUS_OFFLINE: $result[$key]['status_name'] = '已下线'; $result[$key]['action_act'] = '上线'; break; default: return false; } } return $result;
使用引用方法:
foreach($result as &$info){ switch($info['status']){ case self::STATUS_DELETED: $info['status_name'] = '已删除'; $info['action_act'] = ''; break; case self::STATUS_DRAFT: $info['status_name'] = '草稿'; $info['action_act'] = '上线'; break; case self::STATUS_ONLINE: $info['status_name'] = '已上线'; $info['action_act'] = '下线'; break; case self::STATUS_OFFLINE: $info['status_name'] = '已下线'; $info['action_act'] = '上线'; break; default: return false; } } return $result;
结果都是:
Array
(
[0] => Array
(
[id] => 137291
[start] => 192.168.2.11
[end] => 192.168.2.133
[type] => 1
[channel] => 2
[creator_id] => 8369
[editor_id] => 8369
[create_time] => 1547448927
[update_time] => 1547520780
[vendor] => 思特奇
[third_app] => ttt
[status] => 2
[description] =>
[status_name] => 已上线
[action_act] => 下线
)
[1] => Array
(
[id] => 137301
[start] => 192.168.2.11
[end] => 192.168.2.123
[type] => 2
[channel] => 2
[creator_id] => 8369
[editor_id] => 8369
[create_time] => 1547453439
[update_time] => 1547456539
[vendor] => 思特奇
[third_app] => 啊啊
[status] => 2
[description] =>
[status_name] => 已上线
[action_act] => 下线
)
)