/**
* 二维数组排序功能
* @param type $arrays -待排序数组
* @param type $sort_key -按照某个键值排序(例如:add_time)
* @param type $sort_order -排列顺序 SORT_ASC 和 SORT_DESC。
* @param type $sort_type -排序类型 SORT_REGULAR、SORT_NUMERIC和SORT_STRING
* @return 二维数组排序功能
*/
function my_array_multisort($arrays, $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC) {
if (is_array($arrays)) {
foreach ($arrays as $array) {
if (is_array($array)) {
$key_arrays[] = $array[$sort_key];
} else {
return false;
}
}
} else {
return false;
}
array_multisort($key_arrays, $sort_order, $sort_type, $arrays);
return $arrays;
}
/**
* 截取UTF-8编码下字符串的函数
*
* @param string $str 被截取的字符串
* @param int $length 截取的长度
* @param bool $append 是否附加省略号
*
* @return string
*/
function sub_str($str, $length = 0, $append = true)
{
$str = trim($str);
$strlength = strlen($str);
if ($length == 0 || $length >= $strlength)
{
return $str;
}
elseif ($length < 0)
{
$length = $strlength + $length;
if ($length < 0)
{
$length = $strlength;
}
}
if (function_exists('mb_substr'))
{
$newstr = mb_substr($str, 0, $length, EC_CHARSET);
}
elseif (function_exists('iconv_substr'))
{
$newstr = iconv_substr($str, 0, $length, EC_CHARSET);
}
else
{
//$newstr = trim_right(substr($str, 0, $length));
$newstr = substr($str, 0, $length);
}
if ($append && $str != $newstr)
{
$newstr .= '...';
}
return $newstr;
}