为包含等号运算符的where子句获取正确的结果


YaLinqo - Get correct result for where clause containing equals operator

我正在尝试查询一个sql类似语法的数组,我正在了解YaLinqo。

我设法让它工作的地方子句与上级或下级操作符,但我不能让它与等于操作符工作。

我做错了什么?

下面是一个例子:

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);

我发现使用==代替=工作:

// 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();