Echo a Variable

Reply

Join Date: Jul 2007
Posts: 91
Reputation: Reliable is an unknown quantity at this point 
Solved Threads: 2
Reliable Reliable is offline Offline
Junior Poster in Training

Echo a Variable

 
0
  #1
Oct 13th, 2009
I've been echoing variables by simply typing "echo" then the variable. For instance:
  1. <?php
  2. $name = "Me";
  3. echo $name;
  4. ?>
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:

  1. <?php
  2. $username = $_POST['username'];
  3. $password = $_POST['password'];
  4.  
  5. echo "{username} : {$password}";
  6. ?>

Did he do it like that because of the POSTS command? Was this necessary? Help me understand, please? Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
0
  #2
Oct 13th, 2009
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:
  1. echo "My name is {$_GET['name']}<br />";
instead of this:
  1. echo "My name is " . $_GET['name'] . "<br />";
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC