首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >YaLinqo -获取包含等于运算符的where子句的正确结果

YaLinqo -获取包含等于运算符的where子句的正确结果
EN

Stack Overflow用户
提问于 2015-10-07 17:49:04
回答 1查看 833关注 0票数 1

我正在尝试使用类似于SQL的语法来查询数组,并且我开始了解YaLinqo。

我设法让它对带有上级或下级运算符的where子句起作用,但我不能让它对等于运算符起作用。

我做错了什么?

下面是一个示例:

代码语言:javascript
复制
require_once __DIR__ . '/vendor/autoload.php';

use \YaLinqo\Enumerable;

$users = [
    [
        'UserId' => '1',
        'username' => 'joe',
        'password' => 'joepw',
        'mail' => 'joe@mail.com'
    ],
    [
        'UserId' => '2',
        'username' => 'nancy',
        'password' => 'nancypw',
        'mail' => 'nancy@mail.com'
    ],
    [
        'UserId' => '3',
        'username' => 'alice',
        'password' => 'alicepw',
        'mail' => 'alice@mail.com'
    ]
];

$working = \YaLinqo\Enumerable::from($users)
    ->where('$users ==> $users["UserId"] > 2')
    ->toArray();

$notWorking = \YaLinqo\Enumerable::from($users)
    ->where('$users ==> $users["UserId"] = 2')
    ->toArray();

$workingAndUgly = \YaLinqo\Enumerable::from($users)
    ->where('$users ==> $users["UserId"] > 1')
    ->where('$users ==> $users["UserId"] < 3')
    ->toArray();

$notWorkingEither = \YaLinqo\Enumerable::from($users)
    ->where('$users ==> $users["username"] = "nancy"')
    ->toArray();

var_dump($working, $notWorking, $workingAndUgly, $notWorkingEither);
EN

回答 1

Stack Overflow用户

发布于 2015-10-07 19:32:42

我发现使用==而不是=是可行的:

代码语言:javascript
复制
// previously $notWorking
$nowWorking = \YaLinqo\Enumerable::from($users)
    ->where('$users ==> $users["UserId"] == 2')
    ->toArray();

// previously $notWorkingEither
$nowWorkingAlso = \YaLinqo\Enumerable::from($users)
->where('$users ==> $users["username"] == "nancy"')
->toArray();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32989067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档