Skip to content

Instantly share code, notes, and snippets.

View haxianhe's full-sized avatar
🦍
Hello !

haxianhe haxianhe

🦍
Hello !
View GitHub Profile
@haxianhe
haxianhe / aes_ecb_pkcs5.php
Created July 24, 2018 11:58 — forked from CodFrm/aes_ecb_pkcs5.php
PHP对接java的AES/ECB/PKCS5Padding加密方式
<?php
/**
*============================
* author:Farmer
* time:2017/12/19
* blog:blog.icodef.com
* function:加密方式
*============================
*/
@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();
}
@haxianhe
haxianhe / find_key_value.php
Created July 25, 2018 12:46
查找数组中上一个元素键/值,下一个元素键/值
<?php
/*
* 查找数组中上一个元素键/值,下一个元素键/值
* @param str $currentValue 当前元素的值
* @param array $array 待查询数组
* @return array 上一个元素键/值,下一个元素键/值
*/
public function arrayPrevNext($currentValue, $array)
{
$prev_key = $next_key = null;
@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 / 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 / sort.php
Last active January 7, 2020 07:37
PHP 对数据库结果排序(对多维数组排序)
<?php
$data[] = array('volume' => 67, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 1);
$data[] = array('volume' => 85, 'edition' => 6);
$data[] = array('volume' => 98, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 6);
$data[] = array('volume' => 67, 'edition' => 7);
print_r($data);
$column = array_column($data, 'edition');
array_multisort($column, SORT_DESC, $data);
@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 / 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);