php recursive formatting numeric type php code formatting tool sublime php formatting php array format

WBOY
Release: 2016-07-29 08:52:56
Original
1223 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

Use:
day2str('',$data);
Copy after login

The above introduces the PHP recursive formatting number type, including PHP and formatting content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!