<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
function check_device()
{
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $ua = $_SERVER['HTTP_USER_AGENT'];
    } else {
        $ua = '';
    }
    ## This credit must stay intact (Unless you have a deal with @lukasmig or frimerlukas@gmail.com
    ## Made by Lukas Frimer Tholander from Made In Osted Webdesign.
    ## Price will be $2
    $iphone = strstr(strtolower($ua), 'mobile'); //Search for 'mobile' in user-agent (iPhone have that)
    $android = strstr(strtolower($ua), 'android'); //Search for 'android' in user-agent
    $windowsPhone = strstr(strtolower($ua), 'phone'); //Search for 'phone' in user-agent (Windows Phone uses that)

    if (!function_exists('androidTablet')) {

        function androidTablet($ua)
        { //Find out if it is a tablet
            if (strstr(strtolower($ua), 'android')) { //Search for android in user-agent
                if (!strstr(strtolower($ua), 'mobile')) { //If there is no ''mobile' in user-agent (Android have that on their phones, but not tablets)
                    return true;
                }
            }
        }
    }
    $androidTablet = androidTablet($ua); //Do androidTablet function
    $ipad = strstr(strtolower($ua), 'ipad'); //Search for iPad in user-agent

    if ($androidTablet || $ipad) { //If it's a tablet (iPad / Android)
        return 'tablet';
    } elseif ($iphone && !$ipad || $android && !$androidTablet || $windowsPhone) { //If it's a phone and NOT a tablet
        return 'mobile';
    } else { //If it's not a mobile device
        return 'desktop';
    }
}
function validate_date($date)
{
    $d = DateTime::createFromFormat('Y-m-d', $date);
    $d2 = DateTime::createFromFormat('Y/n/d', $date);
    $d3 = DateTime::createFromFormat('n/d/Y', $date);
    // The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
    // return $d && $d->format($format) === $date;
    return $d || $d2 || $d3;
}
function array_unique_fb($array2D)
{
    $temp = [];
    foreach ($array2D as $v) {
        $v = join(",", $v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
        $temp[] = $v;
    }
    $temp = array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v) {
        $temp[$k] = explode(",", $v); //再将拆开的数组重新组装
    }
    return $temp;
}
function var_export_min($var, $return = false) {
    if (is_array($var)) {
        $toImplode = array();
        foreach ($var as $key => $value) {
            $toImplode[] = var_export($key, true).'=>'.var_export_min($value, true);
        }
        $code = 'array('.implode(',', $toImplode).')';
        if ($return) return $code;
        else echo $code;
    } else {
        return var_export($var, $return);
    }
}
