此中将收藏我在工作中用到的一些PHP函数。有自己写的,也会有网上收集的。此文不断更新中
1.打印数组函数 

function _print($array)
{
    
echo ("<pre>");
        
print_r($array);
    
echo ("</pre>");
}

2.截取字串

;
    }
}

3.加载文件

;
}

4.下载文件

;
}

5.数组排序 

代码
/**
* @package     BugFree
* @version     $Id: FunctionsMain.inc.php,v 1.32 2005/09/24 11:38:37 wwccss Exp $
*
*
* Sort an two-dimension array by some level two items use array_multisort() function.
*
* sysSortArray($Array,"Key1","SORT_ASC","SORT_RETULAR","Key2"……)
* @author                      Chunsheng Wang <wwccss@263.net>
* @param  array   $ArrayData   the array to sort.
* @param  string  $KeyName1    the first item to sort by.
* @param  string  $SortOrder1  the order to sort by("SORT_ASC"|"SORT_DESC")
* @param  string  $SortType1   the sort type("SORT_REGULAR"|"SORT_NUMERIC"|"SORT_STRING")
* @return array                sorted array.
*/
    
function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR")
    {    
        
if(!is_array($ArrayData))
        {
            
return $ArrayData;
        }
 
        
// Get args number.
        $ArgCount = func_num_args();
 
        
// Get keys to sort by and put them to SortRule array.
            for($I = 1;$I < $ArgCount;$I ++)
            {
                
$Arg = func_get_arg($I);
            
if(!eregi("SORT",$Arg))
            {
                
$KeyNameList[] = $Arg;
                
$SortRule[]    = '$'.$Arg;
               }
            
else
            {
                
$SortRule[]    = $Arg;
            }
        }
 
        
// Get the values according to the keys and put them to array.
            foreach($ArrayData AS $Key => $Info)
        {
            
foreach($KeyNameList AS $KeyName)
            {
                ${
$KeyName}[$Key= $Info[$KeyName];
            }
        }    
 
        
// Create the eval string and eval it.
        if(count($ArrayData)>0)
        {
            
$EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);';
            
eval ($EvalString);
        }
        
return $ArrayData;
    }

 

 

相关文章:

  • 2022-02-08
  • 2021-10-10
  • 2021-08-25
  • 2021-10-07
  • 2022-01-01
  • 2021-10-16
  • 2021-08-19
  • 2021-10-11
猜你喜欢
  • 2022-12-23
  • 2021-08-02
  • 2021-10-18
  • 2021-10-19
  • 2022-02-06
  • 2021-11-30
  • 2021-10-21
相关资源
相似解决方案