<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 16/3/28
 * Time: 下午5:22
 */

class field_helper
{
    public static function unset_column(&$arr,$fields)
    {
        $keys = explode(',',$fields);
        foreach($arr as $key => $val)
        {
            if(in_array($key,$keys)) {
                unset($arr[$key]);
            }
        }
    }

    public static function validate_null_string(&$datas,$fields,$def_val='')
    {
        $keys = explode(',',$fields);
        foreach($datas as $key => $val)
        {
            if(in_array($key,$keys))
            {
                if(is_null($val)) {
                    $datas[$key] = $def_val;
                }
            }
        }
    }

    public static function validate_null_int(&$datas,$fields,$def_val=0)
    {
        $keys = explode(',',$fields);
        foreach($datas as $key => $val)
        {
            if(in_array($key,$keys))
            {
                if(is_null($val)) {
                    $datas[$key] = $def_val;
                }
            }
        }
    }
    public static function copy_column(&$arDst,$arSrc,$columns)
    {
        $keys = explode(',',$columns);
        foreach($arSrc as $key => $val)
        {
            if(in_array($key,$keys))
            {
                $arDst[$key] = $val;
            }
        }
    }
}