Jump to content

  •  

Photo
- - - - -

P4: Hello World! Echo/Print Comments and Variables

PHP4Beginners

  • Please log in to reply
No replies to this topic

#1 DraxxTV

DraxxTV

    Member

  • SuperGeek
  • PipPip
  • 14 posts

Posted 06 July 2014 - 06:00 PM

In this guide, I will be showing you how you can print messages to the screen in PHP and how to use variables.

 

If you would like to print a message to the screen, you have a couple of options. You can either use echo or print. You can see examples of this below

echo "Hello World -  Via Echo";

print "Hello World - Via Print";

One think you need to make sure to do is whenever you finish a command, you end it with a semicolon ;. Another thing to note is that normally, you can use "" as well as ''.

 

If you are wanting to use variables, you can do this by defining the variable and then giving it a value. You do this by using the $ symbol followed by the name of the variables. This should start with an alphabetical character.You can then give it a value. You can see a few examples of this below

$Variable1="my variable";
$Variable2='my variable'; 
$Array['name']="my name";
$Array["Age"]=17;
$NumberVariable=1;

If we have a variable like those above, we can use the same echo and print commands with them.

echo $Variable1;
echo $Array["Age"];
echo $NumberVariable;






Also tagged with one or more of these keywords: PHP4Beginners