Hey I have some simple php/html:
if( $_POST["name"] || $_POST["age"] )
{
echo "Welcome ". $_POST['name']. "
";
echo "You are ". $_POST['age']. " years old.";
exit();
}
?>
I don't understand why on the second line we use double quotes i.e. $_POST["name"]
but in the echo statement we use $_POST['name'], could someone tell me why these are different? Completely new to PHP...
Answer
It doesn't really matter what quotes you choose. There are several discussions about performance. Indeed double quotes are a tiny bit slower. But the difference is minimal even at 100,000+ iterations.
The only differences are the concenation and escaping:
Concenation
Double quotes:
$b = 1;
echo "Test ".$b; // outputs Test 1
echo "Test $b"; // also outputs Test 1
Single quotes:
$b = 2;
echo 'Test '.$b; // outputs Test 2
echo 'Test $b'; // outputs Test $b
Escaping
Double quotes:
echo "\t";
// outputs actual tab letter
Single quotes
echo '\t';
// outputs \t as plain text.
No comments:
Post a Comment