jdadwilson Posted July 21, 2007 Share Posted July 21, 2007 In several post on this forum and other places I have noted the use of $_POST[something] (no quotes), $_POST['something'] (single quote), and $_POST["something"] (double quote). Which is correct, or does it matter? Link to comment https://forums.phpfreaks.com/topic/61073-question-on-_post/ Share on other sites More sharing options...
markjoe Posted July 21, 2007 Share Posted July 21, 2007 While I always assumed it needed to be quoted, I just tested it and on my server it made no difference. For ease of testing, I tested $_GET, but I'd assume $_POST to react the same way. echo $_GET[x] echo $_GET['x'] echo $_GET["x"] All 3 printed the value. Link to comment https://forums.phpfreaks.com/topic/61073-question-on-_post/#findComment-303949 Share on other sites More sharing options...
trq Posted July 21, 2007 Share Posted July 21, 2007 You can use either single or double quotes. The associative array indexes are simply strings, so either will do, just as within php. Not using any quotes will generate notices because php will first search the global namespace looking for a constant. When it can't find that constant php is smart enough to to try a string with the same value. Link to comment https://forums.phpfreaks.com/topic/61073-question-on-_post/#findComment-303951 Share on other sites More sharing options...
DeadEvil Posted July 21, 2007 Share Posted July 21, 2007 print_r($_GET); echo $_GET['x'] echo $_GET["x"] OR print_r($_POST); echo $_POST['x'] echo $_POST["x"] Link to comment https://forums.phpfreaks.com/topic/61073-question-on-_post/#findComment-303955 Share on other sites More sharing options...
JayBachatero Posted July 21, 2007 Share Posted July 21, 2007 $_GET[x] is mostly seen when used in a string. echo "Hello, $_GET[name] blah..."; mysql_query("SELECT * FROM table WHERE blah = $_GET[blah]'); Link to comment https://forums.phpfreaks.com/topic/61073-question-on-_post/#findComment-303964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.