1、
/* *
* 多维数组排序,array_multisort($array, $order, $sort)为基础
* @param array $array 需要排序的数组
* @param string $sort_param 需要排序的字段
* @param string $order 排序,默认倒叙SORT_DESC,可选SORT_ASC
* @return array|boolean
*/
function my_array_multisort($array, $sort_param, $order = SORT_DESC)
{
$sort = [];
foreach ($array as $value) {
if (isset($value[$sort_param])) {
$sort[] = $value[$sort_param];
} else {
$sort[] = '';
}
}
$res = array_multisort($array, $order, $sort);
if ($res) {
return $array;
} else {
return false;
}
}
2
/**
* @param string $url
* @param mixed $data
* @param string $ssl
* @param number $timeout
* @return mixed
*/
function curl_post($url, $data, $ssl=false, $timeout=15)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl);
curl_setopt($ch, CURLOPT_TIMEOUT, (int)$timeout);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
/**
* @param string $url
* @param mixed $data
* @param string $ssl
* @param number $timeout
* @return mixed
*/
function curl_get($url, $data='', $ssl=false, $timeout=15)
{
$ch = curl_init();
if ($data) {
$url = $url.'?'.http_build_query($data);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl);
curl_setopt($ch, CURLOPT_TIMEOUT, (int)$timeout);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}