search
Homephp教程PHP源码PHP中的Linq-用SQL语法操作PHP数组

<script>ec(2);</script>



最近在看.net的新功能Linq,第一感觉,功能非常实用.
数组,字符串都可以用我们熟悉的 SQL 方式来查询,太方便啦!

就想看看PHP在这方面有没有这样的类库.

不查不知道,一查吓一跳,还真的有类似的类库,命名为PHPLinq.

PHPLinq的首页:
http://www.codeplex.com/PHPLinq

Examples

Examples can be found in the test package in the latest release.

A basic example

Let''s say we have an array of strings and want to select only the strings whose length is

// Create data source<br>$names = array("John", "Peter", "Joe", "Patrick", "Donald", "Eric"); <br> <br>$result = from(''$name'')->in($names)<br>            ->where(''$name => strlen($name)             ->select(''$name''); <br>


Feels familiar to SQL? Yes indeed! No more writing a loop over this array, checking the string''s length, and adding it to a temporary variable.

You may have noticed something strange... What''s that $name => strlen($name)

An advanced example

There are lots of other examples available in the PHPLinq download, but here''s an advanced one... Let''s say we have an array of Employee objects. This array should be sorted by Employee name, then Employee age. We want only Employees whose name has a length of 4 characters. Next thing: we do not want an Employee instance in our result. Instead, the returning array should contain objects containing an e-mail address and a domain name.

First of all, let''s define our data source:

class Employee {<br>    public $Name;<br>    public $Email;<br>    public $Age;<br> <br>    public function __construct($name, $email, $age) {<br>        $this->Name     = $name;<br>        $this->Email     = $email;<br>        $this->Age        = $age;<br>   
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
2 个月不见,人形机器人 Walker S 会叠衣服了2 个月不见,人形机器人 Walker S 会叠衣服了Apr 03, 2024 am 08:01 AM

机器之能报道编辑:吴昕国内版的人形机器人+大模型组队,首次完成叠衣服这类复杂柔性材料的操作任务。随着融合了OpenAI多模态大模型的Figure01揭开神秘面纱,国内同行的相关进展一直备受关注。就在昨天,国内"人形机器人第一股"优必选发布了人形机器人WalkerS深入融合百度文心大模型后的首个Demo,展示了一些有趣的新功能。现在,得到百度文心大模型能力加持的WalkerS是这个样子的。和Figure01一样,WalkerS没有走动,而是站在桌子后面完成一系列任务。它可以听从人类的命令,折叠衣物

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

THE是什么币种,THE币值得投资吗?THE是什么币种,THE币值得投资吗?Feb 21, 2024 pm 03:49 PM

THE是什么币种?THE(TokenizedHealthcareEcosystem)是一种数字货币,利用区块链技术,专注于医疗健康行业的创新和改革。THE币的使命是利用区块链技术提高医疗行业的效率和透明度,推动各方之间更高效的合作,包括患者、医护人员、制药公司和医疗机构。THE币的价值和特点首先,THE币作为一种数字货币,具备了区块链的优势——去中心化、安全性高、交易透明等,让参与者能够信任和依赖这个系统。其次,THE币的独特之处在于它专注于医疗健康行业,借助区块链技术改造了传统医疗体系,提升了

一篇搞懂this指向,赶超70%的前端人一篇搞懂this指向,赶超70%的前端人Sep 06, 2022 pm 05:03 PM

同事因为this指向的问题卡住的bug,vue2的this指向问题,使用了箭头函数,导致拿不到对应的props。当我给他介绍的时候他竟然不知道,随后也刻意的看了一下前端交流群,至今最起码还有70%以上的前端程序员搞不明白,今天给大家分享一下this指向,如果啥都没学会,请给我一个大嘴巴子。

Java中this方法怎么使用Java中this方法怎么使用Apr 18, 2023 pm 01:58 PM

一、this关键字1.this的类型:哪个对象调用就是哪个对象的引用类型二、用法总结1.this.data;//访问属性2.this.func();//访问方法3.this();//调用本类中其他构造方法三、解释用法1.this.data这种是在成员方法中使用让我们来看看不加this会出现什么样的状况classMyDate{publicintyear;publicintmonth;publicintday;publicvoidsetDate(intyear,intmonth,intday){ye

Vue3中setup怎么添加nameVue3中setup怎么添加nameMay 13, 2023 am 09:40 AM

Vue3中name有什么用呢?1.在递归组件的时候需要定义name2.配合keep-aliveincludeexclude可以缓存组件3.在Vue有报错或者调试的时候可以看到组件的nameVue3定义name1.自动生成只要在script开启setup语法糖模式单文件组件会自动根据文件名生成对应的name选项例如Tree.vue那他的name就是Tree自动生成,这样做有一个弊端如果想修改name需要修改组件名称如果有地方import该组件需要一并修改。2.在开启一个script用来定义name

如何查询The Sandbox币最新价格?如何查询The Sandbox币最新价格?Mar 05, 2024 am 11:52 AM

如何查询TheSandbox币最新价格TheSandbox是建立在以太坊区块链上的去中心化游戏平台,使用其原生代币SAND可以购买土地、资产和游戏体验。想要查询SAND最新价格的步骤如下:选择一个可靠的价格查询网站或应用程序。一些常用的价格查询网站包括:CoinMarketCap:https://coinmarketcap.com/Coindesk:https://www.coindesk.com/币安:https://www.binance.com/在网站或应用程序中搜索SAND。查看SAND

jQuery中this的使用技巧解析jQuery中this的使用技巧解析Feb 22, 2024 pm 08:54 PM

jQuery是一种流行的JavaScript库,广泛用于网页开发中的DOM操作和事件处理。其中一个重要的概念就是this关键字的使用。在jQuery中,this代表当前操作的DOM元素,但在不同的上下文中,this的指向可能会有所不同。本文将通过具体的代码示例来解析jQuery中this的使用技巧。首先,让我们来看一个简单的示例:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools