Jump to content

LINQ for PHP / JS Developers - Yalinqo & linq.js


FrancisChung
 Share

Recommended Posts

Does anyone here use a LINQ derivative / port for their projects?

Coming from the .NET World, this is one of the things I miss the most when developing in PHP.
Then I came across these 2 projects.

For PHP : 
https://github.com/Athari/YaLinqo

For JS:

https://github.com/mihaifm/linq

Why I chose those 2 over others :
https://stackoverflow.com/questions/5792388/is-there-something-in-php-equivalent-to-linq-in-c

 

I was wondering if anyone had experience using either one of them AND LINQ in .NET and could share their experiences?

You might wonder why you would use LINQ ? 

The main benefits are better code readability (doing away with if -> then statements),  a unified way of querying data in front and backend (Syntax is SQL derived) and applying paradigms from functional programming (See doing away with if->thens) 

// linq.js - anonymous function
Enumerable.Range(1, 10)
    .where(function(i) { return i % 3 == 0; })
    .select(function(i) { return i * 10; });

 

// Alternative shorter syntax using default variable names
$result2 = from($categories)
    ->orderBy('$v["name"]')
    ->groupJoin(
        from($products)
            ->where('$v["quantity"] > 0')
            ->orderByDescending('$v["quantity"]')
            ->thenBy('$v["name"]'),
        '$v["id"]', '$v["catId"]',
        'array(
            "name" => $v["name"],
            "products" => $e
        )'
    );


 

Link to comment
Share on other sites

 Share

×
×
  • Create New...