gpt4 book ai didi

php - PHP 查询中的左大括号和大括号是什么意思?

转载 作者:行者123 更新时间:2023-11-29 06:38:49 24 4
gpt4 key购买 nike

我遇到了一个程序,其中查询以不同的方式形成,如下所示:

$insert_query = "INSERT INTO projects(project_user_id, project_name, project_body) ";
$insert_query .= "VALUES({project_user_id}, '{$project_name}', '{$project_body});

我知道第二行旨在将其与第一行连接起来,以提高查询的可读性。但让我烦恼的是左大括号和右大括号有什么用?仅仅是为了提高代码的可读性还是相反?

最佳答案

来自PHP Documentation :

Complex (curly) syntax

This isn't called complex because the syntax is complex, but because it allows for the use of complex expressions.

Any scalar variable, array element or object property with a string representation can be included via this syntax. Simply write the expression the same way as it would appear outside the string, and then wrap it in { and }. Since { can not be escaped, this syntax will only be recognised when the $ immediately follows the {.

关于php - PHP 查询中的左大括号和大括号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52567968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com