1、二维数组去重,生成二维数组
private function array_unique_fb($array2D){
$data = array();
foreach($array2D as $key =>$value)
{
$isFind = false;
foreach ($data as $key1=>$value1)
{
if ($value1['OpenID'] == $value['OpenID']) {
$isFind = true;
break;
}
}
if (!$isFind)
{
array_push($data, $value);
}
}
return $data;
}
2、上传图片到服务器
private function saveImage($imgurl)
{
$url='Application/Admin/Public/default/images/';
if(!empty($_FILES)){
// function uprename()
// {
// return time() . rand(1000, 5000);
// }
$rule=time() . rand(1000, 5000);
$upload = new ThinkUpload();// 实例化上传类
$upload->maxSize = 2097152;// 2M
$upload->saveRule = $rule;
$upload->exts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = SITE_DIR.$url;
$upload->savePath = '';// 设置附件上传目录
$upload->thumb = true;
$upload->thumbPrefix = 'm_';
$upload->thumbMaxWidth = '230';
$upload->thumbMaxHeight = '230';
$info = $upload -> uploadOne($imgurl);
// var_dump($info);
// exit;
//将图片上传到本地
if (!$info)
{
// 上传错误提示错误信息
$err = $upload->getError();
$result['result'] = false;
$result['errMsg'] = $err;
return $result;
}
else
{
$image = new ThinkImage();
$open = SITE_DIR.$url.$info['savepath'].$info['savename'];
$image->open($open);
$width = $image->width(); // 返回图片的宽度
$height = $image->height(); // 返回图片的高度
// if($width<230 || $height<230)
// {
// echo "<script>alert('上传图片的高度和宽度均应大于等于230');history.go(-
1);</script>";
// exit();
// }
//将图片裁剪为230x230并保存为corp.jpg
$image->thumb(1423, 550,ThinkImage::IMAGE_THUMB_FIXED)->save( SITE_DIR.$url.$info
['savepath'].'m_'.$info['savename']);
$rootPath = 'Application/Admin/Public/default/images/';
//将头像存储到OSS
$filed = SITE_DIR."Application/Admin/Public/default/images/".$info['savepath'].'m_'.
$info['savename'];
$save_url = "/".$info['savepath'].$info['savename'];
$local_url = $filed;
$file_name= $info['savename'];
$save_type = 'hudong';
$module_name = 'UCenter';
UP($save_url,$local_url,$file_name,$save_type,$module_name);
$ossname = $info['savepath'].$info['savename'];
$url = $rootPath.$info['savepath'].$info['savename'];
//http://hidong-hudong.oss-cn-hangzhou.aliyuncs.com/hudong/UCenter/2015-10-
22/56289782ed389.jpg
return $ossname; // 2015-10-22/56289782ed389.jpg
}
}
}
3、Explode(“,”,$Str) 将字符串转化为数组
Implode(“,”,$Arr) 将数组转化为字符串
Array_push($arr,”sss”) 将字符串插入数组
In_Array( “aa”,$Arr) //判断aa是否在$Arr【一维数组】中