php – Laravel中的所有SQL运算符是什么?

前端之家收集整理的这篇文章主要介绍了php – Laravel中的所有SQL运算符是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在浏览Laravel的源代码,我发现了很多针对Eloquent的sql运算符,我想知道它们中的一些是什么以及如何使用它们.

遗憾的是,我没有设法找到任何文档.

这是我在vendor / laravel / framework / src / Illuminate / Database / Query / Builder.PHP中找到的运算符:

protected $operators = [
    '=','<','>','<=','>=','<>','!=','like','like binary','not like','between','ilike','&','|','^','<<','>>','rlike','regexp','not regexp','~','~*','!~','!~*','similar to','not similar to',];

还有一堆我不明白的.例如:&,|,^,<<,>>,〜,〜*,!〜,!〜*.

谁能告诉我一个如何使用它们的例子?

谢谢

最佳答案
就像其他评论者提到的那样,那些是按位运算符.这里记录了PHP的按位运算符:http://php.net/manual/en/language.operators.bitwise.php

例子

&安培;是bitwise AND操作符.

A bitwise AND takes two equal-length binary representations and@H_502_33@ performs the logical AND operation on each pair of the corresponding@H_502_33@ bits,by multiplying them. Thus,if both bits in the compared position@H_502_33@ are 1,the bit in the resulting binary representation is 1 (1 × 1 =@H_502_33@ 1); otherwise,the result is 0 (1 × 0 = 0 and 0 × 0 = 0)

10& 10 = 10(所有十进制表示).怎么样? 10是1010二进制.

    1010
and 1010
--------
    1010

请注意,仅当同一列中的顶部和底部数字均为1时,结果才为1.

PHP的写作方式:

PHP
echo 10 & 10;
?>
Result: 10

它的实际用途是什么?我们举一个例子:有4套双门.两扇门必须同时打开才能让人通过.打开的门是1号.闭门是2号.

1010表示第一扇门打开,第二扇门打开,第三扇门打开,第四扇门打开.当所有门关闭时,它们看起来像这样:

0000  <-- first set of doors
0000  <-- second set of doors

为了让某人通过最左边的门,门应该是这样的:

0001
0001

这一切都很好,但有一种更快的方式来注释.按位运算符&amp ;.我们做&在两个门之间得到1的结果.因此,如果数据存储为1,我们知道最左边的门是打开的.

要打开最左边的门,组合必须是:

1000
1000

按位运算符的结果是十进制8.使用calculator like the one on miniwebtool运行一些数学运算.

另一方面,当门整天打开和关闭时,可以记录4组门中的任何一扇门都打开时的情况.对于一个简单的问题,这只是一个冗长的答案.

猜你在找的MySQL相关文章