php recursive formatting number type

巴扎黑
Release: 2016-11-09 11:25:10
Original
1126 people have browsed it

  /**
     * 数字转日期递归
     *@param list
     *@return list
     **/
    function day2str($key,$obj,$keys=array('create_time'=>'Y-m-d','s_time'=>'Y-m-d','e_time'=>'Y-m-d','usetime'=>'Y-m-d G:i:s')){
        if(is_array($obj)){//如果是 obj 或 数组 
            foreach ($obj as $k => $v) {
               $obj[$k] = day2str($k,$v,$keys);//递归 
            }
            return $obj;
        }else{
            if(!$type=  $keys[$key] ){//去掉列表没有的项目
                return  $obj; 
            }
            if(is_numeric($key) ){//去掉数组类型
                return $obj;
            }
            if(!$obj){//去掉空值
                return "";
            }
            if(!is_numeric($obj) ){//去掉已转型过的
                return $obj;
            }
            return date($type,$obj);//数字转字串
        }
Copy after login
day2str('',$data);
Copy after login


Related labels:
php
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