PHP lecture 2....




>> VARIABLE IN PHP :--- 

 

Variables are containers which is used to store information.


Types of Variables:--

1. Local Variable.

2. Global Variable.

3. Static Variable.

>>VARIABLE DECLARATION :--

In PHP, variable names begin with "$" sign, followed by a name. Ex :- $roll, $price, $name.

>> RULES FOR DECLARING VARIABLES :--


1. Variable starts with '$' sign.

2. Variable name only starts with a letter, an underscore(_).

3. Variable name cannot start with a number.

4. It is case sensitive.

5. Do not use predefined constant name. For ex :- PHP_VERSION, PHP_OS, etc....

6. Do not use reserved keywords. For ex :- else, if, etc....


>> VARIABLE INITIALIZATION :--

 

PHP can store all type of data in variables. Before using  a variable in PHP, we have to assign a value to it, so that PHP will create that variable and store data in it. That means we have to assign data to a variable before attempting to read a variable's value.
For ex :- $roll = 256;
                $price = 25.50;
                 $name = "DragonBallZ";

NOTE :--  If a variable is created without a value, it is automatically assigned a value of NULL.


>> INTERNAL DATA TYPES IN PHP :--


In other language, we need to specify exact data format of each variable, but here PHP handle this work for us.

1. Integer :- It can hold whole number. Ex :- 12, 0, -34, etc....

2. Float/Double :- It can hold floating point numbers. Ex :- 25.456, etc....

3. String :- It can hold text or group of characters. Ex :- "DragonBallZ", etc....

4. Boolean :- It can hold true/false value.

5. Array :- It can hold multiple values in one single variable.

6. Objects :- It can hold programming objects.

7. Resources :- It is a special variable that hold references to resources external to PHP.

8. NULL :- It can hold only one value, which is NULL.



>> ECHO IN PHP :---


This statement is used to output the data to the screen or print text on screen.
Ex :- echo"DragonBallZ";
         echo'DragonBallZ';
         echo 25.25;
         echo("DragonBallZ");
         echo"DragonBall"."Super";  (Dot is used for concatenation).


>> PRINT IN PHP :--


It performs same work as echo. Only few little things that make it different from echo.



>> PRINT  VS  ECHO


1. 'Echo' has no return value while 'Print' is more like php function so it returns value, which is always set to 1.

2. 'Echo' can take multiple parameters while 'Print' can take one argument.

3. 'Echo' is marginally faster than 'Print'.



>>HERE DOCUMENT


Here document is another way of displaying text. A here document is just some text inserted directly in a PHP page. We can write multiple lines without quotes.
 SYNTAX :--
echo<<<Token
  ----------------
------------------
Token;

Note : Token is a word that begins and ends the Here document.

Example :- <?php
echo<<<Myfav
Dragon Ball Z
Dragon Ball Super
Dragon Ball Heroes.
Myfav;
?>
Note : There is no space before ending Token.



>>COMMENTS


 Comments are those human readable text that we should add to make code more understandable for other programmers and they are ignored by PHP.

>>Types Of Comments :-

1. One Or Single Line Comment.

There are two types of single line comment in php.

a: Starts with //
ex:- //Dragon Ball Z.

b: Starts with #
ex:- #Dragon Ball Z.


2. Multi-line Comments.

  Starts with /* and ends with */.
ex:- /*Dragon Ball Z
          Dragon Ball GT*/.


     Read More                                                                                                                        

Comments

Popular posts from this blog

Addicted To Infinite Scrolling: The Dark Side Of Social Media

Coding for Everyone? My Personal Journey and Lessons Learned

The Dark Truth Behind Apple's Privacy Claims - Is Your Data Really Safe?