Skip to content

Instantly share code, notes, and snippets.

View haxianhe's full-sized avatar
🦍
Hello !

haxianhe haxianhe

🦍
Hello !
View GitHub Profile
@haxianhe
haxianhe / LambdaTest.java
Last active December 27, 2021 13:16
Lambad case
package com.haxianhe;
import static com.haxianhe.ClassA.test;
import java.util.function.Predicate;
/**
* @author haxianhe <haxianhe@gmail.com>
* Created on 2021-12-27
*/
@haxianhe
haxianhe / CSV.php
Created January 7, 2021 06:40
csv处理函数
<?php
/**
* @Desc: csv处理函数
* @User: haxianhe
* @Date: 2019/4/2
* @Time: 5:03 PM
*/
abstract class CSV
{
@haxianhe
haxianhe / page.php
Last active April 30, 2020 06:22
分页
<?php
//获取分页
public static function getOffsetLimit($page = 1, $perpage = 50) {
if (empty($perpage)) {
$perpage = 50;
}
$page = max(1, $page);
$page = min(1000000, $page);
$perpage = max($perpage, 1);
$perpage = min(10000, $perpage);
@haxianhe
haxianhe / writeFormatCsvFile.php
Created April 19, 2020 23:49
格式化数据写入到文件中, 主要是写csv文件
<?php
/**
* brief: 格式化数据写入到文件中, 主要是写csv文件
*
* @param $arrData //要写入是的数据。二位数组。[['title' => '标题1', 'title2' => '标题2']]
* @param $arrTitle //标题,一维数组。定义顺序。和数据的key一致。
* @param $filepath //写入文件路径
* @param $write_type //1: 保留原来数据,往后插入。 2: 保留原来数据,在头部写入. 注意,如果是文件头写入,是覆盖式写入,不是插入式。且从第一行开始. 这个时候就需要预先写入空行,且空行占用字节数应该大于等于要写入头部的字节数。否则会覆盖。
*
* @return bool
@haxianhe
haxianhe / judgeArrayEquals.php
Last active August 5, 2019 04:14
判断两个数组是否相等
<? php
/*
* 判断两个数组是否相等
*/
public static function judgeArrayEquals($array1, $array2)
{
if (!is_array($array1) || !is_array($array2)) {
return false;
}
@haxianhe
haxianhe / user_array_filter.php
Created July 12, 2019 06:26
php 过滤数组元素
<?php
$abnormalOrderIds = array_filter($abnormalOrderIds, function ($item) use ($completeOrders) {
return !isset($completeOrders[$item['code']]);
});
@haxianhe
haxianhe / array_group_by.php
Last active January 5, 2021 09:47
php数组按某一个元素值进行分组,正如数据库的group by语句
<?php
/**
* 数组按某一个元素值进行分组,正如数据库的group by语句
* @param $array
* @param $key
* @return array
*/
public function array_group_by($array, $key)
{
@haxianhe
haxianhe / get_array_need.php
Last active July 12, 2019 06:19
php 过滤数组中有需要的键值对
<?php
public function filterArray($oldArray,$keyArray)
{
$newArray=array_intersect_key($oldArray, array_flip($keyArray));
return $newArray;
}
$promotion = array_intersect_key($promotion, array('id', 'promotion_id', 'promotion_actived', 'promotion_title',
'promotion_detail', 'promotion_type', 'promotion_type_name', 'sku_info', 'start_time', 'cancel_time','effect_scene'));
@haxianhe
haxianhe / unique_array_more.php
Last active July 12, 2019 06:19
php 二维数组去掉重复值
<? php
/**
* 对二维数组去重
* @param $array2D
* @return array
*/
function unique_array_more($array2D)
{
foreach ($array2D[0] as $key => $value) {
@haxianhe
haxianhe / trait.php
Last active July 12, 2019 06:22
PHP 用trait实现的单例
<?php
trait Service_Data_Base_Singleton
{
private static $singleton;
private function __construct(){}
public static function getInstance() {
if( !(self::$singleton instanceof self) ) {
self::$singleton = new self();
}