Code Monkey home page Code Monkey logo

alinq's Introduction

alinq

a branche of the libarary Plinq(http://plinq.codeplex.com/license) which is a implementation of linq to array.
基于Plinq(http://plinq.codeplex.com/license) 修改的一个以linq方式操作数组的php类. ##The Purpose of Branche This branche of the libaray trying to implemente the same feature without using SPL RecursiveArrayIterator;
这个分支试图在不依赖SPL RecursiveArrayIterator 这个标准库的情况下,实现与原Plinq同样的功能

##Differences

  • This branche add a new method Instance to Instance the Alinq class without using "new" keyword. Sometimes it's usefull,like the libaray live on a framework.
    Here giving a example: 这个分支添加了一个新的方法:Instance,以传入的数组来实例化Alinq类,而不必使用new 关键字.
    这在某些情况下还是有点用的,比如在框架代码中调用这个类的时候。
    下面给出例子:
include('Alinq.php');

$alinq = new Alinq($array);
$otherAlinq = $alinq->Instance($newArray);
  • Another difference is that some result of the this library are objects which could not used as array . The result object should call it's ToArray method to get array result.
    另外一个不同之处在与类库返回的结果,这个分支返回的对象结果不能直接作为数组使用,对象结果可以通过调用自身的ToArray方法来的到数组结果。 example:
include('Alinq.php');

$alinq = new Alinq($array);
$result = $alinq->Select(function($k, $v){ return $v['int']; })->ToArray();

Alinq methods that will return object:

  • Instance()
  • Single()
  • GroupBy()
  • Concat()
  • SelectMany()
  • Select()
  • Where()
  • Skip()
  • Take()
  • All()
  • Any()
  • Average()
  • OrderBy()
  • OrderByDescending()
  • Max()
  • Min()
  • count()
  • Distinct()
  • Intersect()
  • Diff()
  • ElementAt()
  • First()
  • Last()
  • Array2DInverse()
  • ToArray()

Requirements

  • PHP 5.3 or higher -- because of it depends on the new feature closures in PHP 5.3

Usage

include('Alinq.php');
$p = new Plinq($testArray);
$result = $p->Where(function($k, $v){ return ($v['int'] > 998); })->ToArray();

##Running tests install phpunit

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit

run phpunit

phpunit --verbose test/AlinqTest.php

alinq's People

Contributors

wosiwo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

guojianbin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.