ThinkPHP 中 where条件 or,and 同时使用~请大神出现~

('a'=1 or 'b'=2) and ('c'=3 or ( 'd'=4 and 'e'=5 ))

请不要使用字符串_string,只用_logic和_complex。谢谢

$where['_complex'] = [
    [
        'a' => 1, 
        'b' => 2, 
        '_logic' => 'or'
    ],
    [
        'c' => 3, 
        '_complex' => [
            'd' => 4, 
            'e' => 5
        ], 
        '_logic' => 'or'
    ]
];

如不提供_logic属性,则thinkphp使用默认属性and进行条件连接。

也就是(结构补充完整):

$where['_complex'] = [
    [
        'a' => 1, 
        'b' => 2, 
        '_logic' => 'or'
    ],
    [
        'c' => 3, 
        '_complex' => [
            'd' => 4, 
            'e' => 5,
            '_logic' => 'and', //这一行可缺损
        ], 
        '_logic' => 'or'
    ]
];

温馨提示:答案为网友推荐,仅供参考
相似回答