开发者

how do i parse an array element within double-quotes

Is there more elegant way of escaping array elements:

mysql_开发者_开发技巧query("SELECT * from mytable WHERE name = '".$someArray['somename']."'");

Something more like

mysql_query("SELECT * from mytable WHERE name = '$myname'");

So avoiding the annoying '". ."'"


You can use:

mysql_query("SELECT * from mytable WHERE name = '{$someArray['somename']}'");


You can actually do:

mysql_query("SELECT * from mytable WHERE name = '{$foo[bar]}'");

But I would advise against it or any other parsed string, it's slower than concatenation and is much harder to read in some IDEs.


$myname = $someArray['somename'];
mysql_query("SELECT * from mytable WHERE name = '$myname'");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜