Secret mind

hi Friends, I am Aman gupta and a web developer. I learned many languages such as java, javaScript, python, clang, php, jquery, mysql database, Html and css and many more just to make a perfect and wonderfully website. Here i will upload related post of PHP, Secret of world, computer science, Feelings, GK, And Question paper.

Trending video

Responsive Ads Here

الاثنين، 30 ديسمبر 2019

PHP tutorial part 2

PHP TUTORIAL (part 2)

aman gupta

Comments in PHP

// it is a single line comment 

/* it is a multipul line comments*/


About Variables in PHP

Variables in a program are used to store some values or data that can be used later in a program. PHP has its own way of declaring and storing variables.variables are containers which is used to store information.some points are given below:

  1. you don't need to bother about data type of the variable.
  2. Every variable name will start by $ sign. Ex. $variable_Secretmind
  3. Name of the variable must be start from alphabet not from the numbers.
  4. you can't give space in variable name.
  5. you can't use keywords as a variable name.
example:

<?php
$x=5;
$y=5;

$z= $x+$y;

echo "Answer is $z";
?>

Variable Scopes

Scope of a variable is defined as its extent in program within which it can be accessed, i.e. the scope of a variable is the portion of the program with in which it is visible or can be accessed.

Depending on the scopes, PHP has three variable scopes:


1.Local variables: The variables declared within a function are called local variables to that function and has its scope only in that particular function. In simple words it cannot be accessed outside that function. Any declaration of a variable outside the function with same name as that of the one within the function is a complete different variable. We will learn about functions in details in later articles. For now consider a function as a block of statements.

Example:

<?php
$x=4;
function aman(){
$x=0;
print("inside function value of x is $x");

}
aman();
print("outside function value is $x");
?>
2.Global variables: The variables declared outside a function are called global variables. These variables can be accessed directly outside a function. To get access within a function we need to use the “global” keyword before the variable to refer to the global variable.
Example:
<?php
$x=4;
function aman(){
GLOBAL $x;
print("inside function value of x is $x");

}
aman();
print("outside function value is $x");
?>
3.Static variable: It is the characteristic of PHP to delete the variable, ones it completes its execution and the memory is freed. But sometimes we need to store the variables even after the completion of function execution. To do this we use static keyword and the variables are then called as static variables.
Example:

<?php 
// function to demonstrate static variables 
function static_var() 
{    
    // static variable 
    static $num = 5; 
    $sum = 2;   
    $sum++; 
    $num++; 
    echo $num, "\n"; 
    echo $sum, "\n"; 
// first function call 
static_var(); 
// second function call 
static_var(); 
?> 

Basic Types of Operators in PHP

Operators are symbols that tell the PHP processor to perform certain actions. For example, the addition (+) symbol is an operator that tells PHP to add two variables or values, while the greater-than (>) symbol is an operator that tells PHP to compare two values.Operators are used to perform operations on variables and values.PHP divides the operators in the following groups:

  1. Concatenation Operators( . )
  2. Arithmetic Operators ( +, - , / , * , %)
  3. Assignment Operators( = )
  4. Increment/Decrement Operators( ++ , -- )
  5. Comparison Operators( == ,=== , < , > , <= , >= )

Question 
1.Different between  global variable and static variable .
2.What is the super global variable ? And describe all parts of super global variable.
3.Describe 3 variable scope.
4. What is operators in PHP ? Describe Assignment or increment/ Decrement operators.


ليست هناك تعليقات:

إرسال تعليق

Please do not enter any spam link in the comment box.