Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query on PHP arrays

Consider following scenario: You have a small MogoDB collection or a small MySQL table (contains 1000 record for example, it may be read-only too ) that is used extensively and repeatedly in your app.

You decide to fetch all of its content to a PHP array and use the array instead of sending a lot of query to DB.

In above scenario how can we retrieve some array items in a manner similar to retrieving records of a DB table in an efficient way? A PDO adapter for array or any other similar facility ...

like image 417
Handsome Nerd Avatar asked Apr 12 '26 09:04

Handsome Nerd


1 Answers

There is port of famous C# LINQ library for php.

It gives you flexible oo interface to querying data sources.

http://phplinq.codeplex.com/wikipage?title=Examples&referringTitle=Home

Simple example

// Create data source
$names = array("John", "Peter", "Joe", "Patrick", "Donald", "Eric"); 

$result = from('$name')->in($names)
            ->where('$name => strlen($name) < 5')
            ->select('$name'); 
like image 50
Fivell Avatar answered Apr 14 '26 21:04

Fivell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!