Friday, September 27, 2013

PHP Part-2

Hi friends, this is my second blog on PHP and today we will learn about:
  • How to create and store variables?
  • What echo do?
  •  How to give comment?
  • What is heredoc?
Variable: By using variables we can store strings, a word or a number. In PHP, data types are assigned automatically. There is no need to assign data types manually.   
Variable form:
          $variable_name=value;
This variable name is case sensitive. There are some standard ways to write variable name:
1.     Name of the variable must start with alphabetic word or “_”.
2.     Variable name must consist only of alpha-numeric words and underscores.
3.     If there is more than one word in variable then it must be separated by “_” or by capitalization.

    Echo: Echo is used to output the string. Echo uses quotes (“ “) to define beginning and end of the string. At the time of echoing variable there is no need for quotations.

    Comment: Comments are used to document the project or code.
For single line comments (//) are used and for multiline comments (/*……….*/).

 String: There are two types of strings:
1.     Stored string: $my_string= ”Hey Jak”;
echo $my_string;
2.     Direct string: echo “ Hi Jak “;
Strings are quoted in two ways, double quotes (“ ”) and single quotes(‘ ‘).
 sHeredoc: This is the unique feature of PHP, it lets programmer create multi-line strings without using quotes. It begin with (<<<) and some identifier and it ends with identifier followed by semi-colon (;).

 Example: example demonstrating use of variable, comment, echo and heredoc.