Skip to content

Instantly share code, notes, and snippets.

@phpdever
phpdever / countArray.php
Last active January 28, 2023 02:35
php 数组去重计数
<?php
// 原始数组
$primitiveArray = [
[1, 2, ''],
[2, ''],
[2, ''],
[2, 4, ''],
[1, 2, 3, ''],
[2, 3, ''],
@phpdever
phpdever / mongodb-sum
Created August 23, 2019 08:54
MongoDB 聚合查询 Sum 多个字段
db.test.aggregate([
{
$project: {
_id: null,
Month: {
$cond: {
if: {$eq: ["$month", 3]},
then: 1,
else: 0
}
@phpdever
phpdever / foreach_order
Created May 9, 2017 09:41
关于php循环读取数据表,并对其进行排序无效的问题
$result = json_decode($json,true);
foreach($result['result']['items'] as $key=>$val){
$where['id'] = array('eq',$val['id']);
$items = M('item')->where($where)->order('id asc')->select();
}
public function getDown(&$fenxiaos,$userid){
$user=M('user');
$where = array(
'shares_tree' => array('like','%|'.$userid.'|-%'),
'status' => 1,
'uid'=>array('in',array('2','3','5'))
);
$users=$user->where($where)->field('id')->select();
foreach($users as $key=>$value){
$fenxiaos[] = $value['id'];