双引号内的变量 [英] Variable within double quotes

查看:49
本文介绍了双引号内的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个是正确的语法?

$current_renewal_date = $wpdb->get_results(
                    "
                    SELECT expiry_date
                    FROM bid_tag
                    WHERE id = $renewal_tag_id
                    LIMIT 1
                    "
                );

$current_renewal_date = $wpdb->get_results(
                    "
                    SELECT expiry_date
                    FROM bid_tag
                    WHERE id = {$renewal_tag_id}
                    LIMIT 1
                    "
                );

推荐答案

两者都是正确的.后者只是用来避免歧义,就像你想引用 $foo 而不是 $foobar:

Both are correct. The latter is just used to avoid ambiguity like if you want to reference $foo and not $foobar:

"{$foo}bar"

这篇关于双引号内的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆