Re: why use {} around vraiable?
| From: | Ray Hauge | Date: | Thu, 20 Mar 2008 16:37:46 +0000 |
| Subject: | Re: why use {} around vraiable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271908@lists.php.net to get a copy of this message | ||
Lamp Lists wrote:
hi, I saw several times that some people use this $parameters = array( 'param1' => "{$_POST["param1"]}", 'param2' => "{$_POST["param2"]}" ); or $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'"); I would use: $parameters = array( 'param1' => $_POST["param1"], 'param2' => $_POST["param2"] ); and $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." ' "); does it really matter? is there really difference or these are just two "styles"? thanks. -llThe brackets are used to enforce that the entire contents between them is a variable. It helps when you're using class members. $example = "this is an {$example->text}"; It's also handy when you're putting variables in a heredoc. I would suggest not using "{$_POST["param1"]}", like you said. It's just going to make PHP figure out the string, then put the value in that string. If you really wanted to make sure it's a string type then you can do (string)$_POST['param1']. The short answer is you can do it the way you're doing and everything will work out just fine :) -- Ray Hauge www.primateapplications.com____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ