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

93 lines
2.3 KiB
PHTML

<?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;
}