文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP Array 常用排序及数据高级操作的 API Engine代码

PHP Array 常用排序及数据高级操作的 API Engine代码

时间:2008-05-17  来源:剑心通明


array(’a’,’1’,’A’),1=>array(’b’,’2’,’B’));
*             $index = 1;
*             usort($exar,"ORD_ASC");  || usort($exar,"ORD_DESC");
*              
*         3. void function DATE_ASC / DATE_DESC
*             配合 global $index 及 php 自带函数 usort() 使用,usort()查看php手册
*  
*             @example:
*             $exar = array(0=>array(’2005-08-21 13:21:77’,’A’),1=>array(’2007-12-11 11:21:77’,’B’));
*             $index = 0;
*             usort($exar,"DATE_ASC");  || usort($exar,"DATE_DESC");
*  
*         4. void array ARY_UTG($index,$arr,$Type = true,$format_string)
*             $index 数组字段索引
*             $arr 源数组
*             $type 数组级别 true 为二维数组(默认),false为一维数组
*             $format_string 格林威治时间样式 默认为 "Y-m-d H:i:s"
*              
*             @example:
*             $exar = array(array(1176731096,’c1932’),array(1076731096,’i1932’));
*             $exar = ARY_UTG(0,$exar);
*             print_r($exar);
*  
*         5. void array ARY_GTU($index,$arr,$Type = true)
*             $index 数组字段索引
*             $arr 源数组
*             $type 数组级别 true 为二维数组(默认),false为一维数组
*              
*             @example:
*             $exar = array(array(’2003-03-28 22:31:21’,’f1932’),array(’2005-07-18 22:31:21’,’i1932’));
*             $exar = ARY_UTG(0,$exar);
*             print_r($exar);
*/
global $Index;
/**
* 把格林威治时间转为时间戳
*/
function GmtToUnix($GmtDate)
{
    $DateArr = explode(’ ’,$GmtDate); // 分割GMT日期为 日期 时间
    /* 在日期中取得年,月,日 */
    $pDate = split(’[/.-]’,$DateArr[0]);
    $Year = $pDate[0];
    $Month = $pDate[1];
    $Day = $pDate[2];
     
    /* 在时间中取得时,分,秒 */
    $pTime = split(’[:.-]’,$DateArr[1]);
    $Hour = $pTime[0];
    $Minute = $pTime[1];
    $Second = $pTime[2];
     
    if($Year == ’’ || !is_numeric($Year))$Year = 0;
    if($Month == ’’ || !is_numeric($Month))$Month = 0;
    if($Day == ’’ || !is_numeric($Day))$Day = 0;
    if($Hour == ’’ || !is_numeric($Hour))$Hour = 0;
    if($Minute == ’’ || !is_numeric($Minute))$Minute = 0;
    if($Second == ’’ || !is_numeric($Second))$Second = 0;
     
    return mktime($Hour,$Minute,$Second,$Month,$Day,$Year);
}
/**
* 对大小写字母和数字进行升序排列
*/
function ORD_ASC($ax,$ay)
{
    global $Index;
if($ax[$Index] == $ay[$Index]) {
        return 0;
    } elseif($ax[$Index]  $ay[$Index]) {
        return -1;
    } else {
        return 1;
    }
}
/**
* 对日期字符进行升序排列
*/
function DATE_ASC($ax,$ay)
{
    global $Index;
    if(GmtToUnix($ax[$Index]) == GmtToUnix($ay[$Index])) {
        return 0;
    } elseif(GmtToUnix($ax[$Index])  GmtToUnix($ay[$Index])) {
        return -1;
    } else {
        return 1;
    }
}
/**
* 对数据集数组的时间戳转换为格林威治时间
* $index 需要修改数据的数组字段
* $Type 数组类型,一维为true 二维为false, 最高支持二维,默认二维
* $arr 源数组
* $format_string 将时间戳格式为以为 $format_string 为例的时间样式
* array(array(’a1932’,1176731096,’c1932’))
*/
function ARY_UTG($index = 0, $arr, $Type = true, $format_string = "Y-m-d H:i:s")
{
    reset($arr);
    if($Type){
        foreach ($arr as $k => $value) {
            $arr[$k][$index] = @gmdate($format_string,$arr[$k][$index]);
        }
    } else {
        foreach ($arr as $k => $value) {
            $arr[$index] = @gmdate($format_string,$arr[$index]);
        }
    }
    return $arr;
}
/**
* 对数据集数组的格林威治时间转换为时间戳
* $index 需要修改数据的数组字段
* $Type 数组类型,一维为true 二维为false, 最高支持二维,默认二维
* $arr 源数组
* array(array(’a1932’,1176731096,’c1932’))
*/
function ARY_GTU($index = 0, $arr, $Type = true)
{
    reset($arr);
    if($Type){
        foreach ($arr as $k => $value) {
            $arr[$k][$index] = GmtToUnix($arr[$k][$index]);
        }
    } else {
        foreach ($arr as $k => $value) {
            $arr[$index] = GmtToUnix($arr[$index]);
        }
    }
    return $arr;
}
?>
具体使用
[url=javascript:;]方法[/url]
,在类内已经有说明,请根据类内介绍进行使用。
    此API为了读者能更有效的操作复杂数据及排序有着重要作用。笔者在研究PHP开发中所经常遇到的问题。
文章转自:
http://www.zxbc.cn/html/phpjc/0108114972992.html


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载