You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/webht/third_party/trippestOrderSync/helpers/array_helper.php

111 lines
3.0 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function array_unique_fb($array2D)
{
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 my_array_unique($array, $keep_key_assoc = false)
{
$duplicate_keys = array();
$tmp = array();
foreach ($array as $key=>$val)
{
// convert objects to arrays, in_array() does not support objects
if (is_object($val))
$val = (array)$val;
if (!in_array($val, $tmp))
$tmp[] = $val;
else
$duplicate_keys[] = $key;
}
foreach ($duplicate_keys as $key)
unset($array[$key]);
return $keep_key_assoc ? $array : array_values($array);
}
//根据URL获取月份
function getaqiMonth($url){
$monArr = array('January','February','March','April','May','June','July','August','September','October','November','December');
$monObj = array(
'January' => '01',
'February' => '02',
'March' => '03',
'April' => '04',
'May' => '05' ,
'June' => '06',
'July' => '07',
'August' => '08',
'September' => '09',
'October' => '10',
'November' => '11',
'December' => '12');
$urlarr = explode("/",$url);
$tmp = $urlarr[(count($urlarr)-1)];
$tmp = ucfirst(str_ireplace('.htm','',$tmp));
//$d=strtotime("00:01am ".$tmp." 15 2015");
if(in_array($tmp,$monArr)){
return $monObj[$tmp];
}else{
return false;
}
}
/*
* 把数组元素组合为字符串
* $container:用来包含元素的符号
* $se:分隔符
* $arr需要重新组合的数组
* 例如:$arr=['aaaa','bbbb'];
* my_implode("'",",",$arr);得到
* 'aaaa','bbbb'
*/
function my_implode($container,$se,$arr)
{
$str = "";
if ($arr != '') {
$str = "";
$tcount = count($arr);
$tcountInt = 0;
foreach ($arr as $i) {
$tcountInt++;
if ($tcount == $tcountInt) {
$str .= $container . $i . $container;
} else {
$str .= $container . $i . $container . $se;
}
}
}
return $str;
}
/*!
* json_encode($a, JSON_UNESCAPED_UNICODE )
* for PHP Version < 5.4
*/
function raw_json_encode($input, $flags = 0) {
$fails = implode('|', array_filter(array(
'\\\\',
$flags & JSON_HEX_TAG ? 'u003[CE]' : '',
$flags & JSON_HEX_AMP ? 'u0026' : '',
$flags & JSON_HEX_APOS ? 'u0027' : '',
$flags & JSON_HEX_QUOT ? 'u0022' : '',
)));
$pattern = "/\\\\(?:(?:$fails)(*SKIP)(*FAIL)|u([0-9a-fA-F]{4}))/";
$callback = function ($m) {
return html_entity_decode("&#x$m[1];", ENT_QUOTES, 'UTF-8');
};
return preg_replace_callback($pattern, $callback, json_encode($input, $flags));
}