I've been echoing variables by simply typing "echo" then the variable. For instance:

<?php  
$name =  "Me";
 echo $name;
?>

This has been working just fine. I was watchign a tutorial and when he echoed his variable he put his in curly brackets. This is the example:

<?php
$username = $_POST['username'];
$password = $_POST['password'];

echo "{username} : {$password}";
?>

Did he do it like that because of the POSTS command? Was this necessary? Help me understand, please? Thanks

Its not needed there, there are a couple of uses for the braces, such as variable variables, but I believe the most common use is to include array vars in a string.

For example:

echo "My name is {$_GET['name']}<br />";

instead of this:

echo "My name is " . $_GET['name'] . "<br />";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.