Quick Start

Download LINQ for PHP

Try our Releases tab, there you can find an actual release with samples. Download it and save into folder, which webserver (like IIS with PHP enabled) can access. For the best results, try LINQ for PHP with the newest PHP 5.2 versions.

Run the samples

In your favourite text editor, open the index.php file. There is line calling Linq1 (or other number) method. You can provide any number from 1 to 14 and the example will run, if you type index.php with the adress of folder, where you store this library. These examples are rewritten from SampleQueries folder of official Microsoft set of LINQ samples


In you own program, you can easily write you own queries. Try to think, you have this C# query:
from n in new int[] { 1, 2, 3 } where n % 2 == 0 select n * 2;
With LINQ for PHP you can write the same query in PHP:
from('$n')->in(array(1,2,3))->where('$n % 2 == 0')->select('$n *2');

  • Every C# keyword is function or method, remeber to () and ->
  • In from, where and select, there are single quoted arguments!
  • That's simple and nice!
LINQ for PHP has a support for method syntax too!

Method syntax

For method syntax, you must have some object ot call methods. For this situation, LINQ for PHP provides a Collections "namespace" with List and Dictionary classes like their .NET concurents.
$list = new LinqForPhp_Collections_List(array(1,2,3));

(Rember to include the file LinqForPhp/Collections/List.php!)
Now, you can write a method query!
list.Where(n => n % 2 == 0).Select(n => n * 2);
$list->Where('$n => $n % 2 == 0')->Select('$n => $n * 2');


Last edited Nov 1, 2008 at 8:46 PM by vojtechzicha, version 3


No comments yet.