Home >Backend Development >PHP Tutorial >php recursive formatting numeric type php code formatting tool sublime php formatting php array format

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:52:561323browse
    /**
     * 数字转日期递归
     *@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);//数字转字串
        }

Use:
day2str('',$data);

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.

Statement:
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