Hello guys,
i want to simple like this
echo "$_POST['id']" . $_POST['id'];
so how can i print this string and its value.
Hello guys,
i want to simple like this
echo "$_POST['id']" . $_POST['id'];
so how can i print this string and its value.
echo '$_POST["id"]' . $_POST['id']
If you have a variable $x='abc' and you do
echo '$x'
it prints $x
and if you do
echo "$x"
it prints abc
Simply put, whatever variables you put into the double quotes get replaces by their values. If you use simple quotes the variables are not replaced.
See http://php.net/manual/en/function.echo.php for more information.
echo '$_POST[\'id\']' . $_POST['id'];
Single quotes '
print a literal string, variables within double quotes "
are evaluated. Note that you have to escape single quotes within a single quoted string.
Alternatively escape the variable within double quotes to prevent it from being evaluated:
echo "\$_POST['id']" . $_POST['id'];
Reference: http://php.net/manual/en/language.types.string.php
Any of these will basically do what you want:
echo "\$_POST['id']" . $_POST['id']; echo '$_POST[\'id\']' . $_POST['id']; echo '$_POST["id"]' . $_POST['id'];
When you use double-quotes, PHP will try to expand variable references inside of the string. You can prevent variable expansions by using backslash to escape the dollar-sign part of the variable reference.
You can also use single-quotes to prevent variable expansions but if you need to actually print a single-quote then you need to use backslash to escape the single-quote.
This doesn't specifically answer your question, but do you know about this?
print_r($_POST);
If you are just looking for some simple way to help you debug, this is very useful. If you want it nice, you can put <pre></pre>
around it.