Monday, 30 May 2016

PHP Variables

What is Variables in PHP?

A variable is just a "container" area where we store the information (Like string or  integer or or arrays value).  PHP automatically convert Variables data types according  its value.

<?php
    $text = "strings variable";
    $number = 5;
?>

Note:
  1. Variable names should be case-sensitive, and In PHP variables are denoted with ($) dollar.
  2. A variable name can not start with a number (means only contain alpha-numeric characters and underscores).
  3. A variable name can not contain spaces. 

What is Constants Variable  in PHP?


A constant Variable can't change at execution time.
Constant Variable is defined using define() function,which accepts two arguments: the name of the constant, and its value.


<?php
    // Defining constants
    define("SITE_URL", "https://phplanguagecode.blogspot.com/");
   

    // Using constants
    echo "Visit my website ".SITE_URL;
    ?>
if you use  SITE_URL any where then its show full url.

What is Variable References?

PHP also allows to create aliases or reference for variables, means a aliases is a variable, that assigned to or refer to the same information as another variable.

<?php
$a = 'nice day!';          
$b = &$a;
$b = "Have a  $b";
?>

Super global Variables.

 PHP has several predefined variables these are called Super Globals. The PHP superglobal variables are:
  1. $GLOBALS
  2. $_SESSION
  3. $_SERVER
  4. $_COOKIE
  5. $_GET
  6. $_POST
  7. $_REQUEST
  8. $_FILES
  9. $_ENV

PHP $_SERVER

which holds information about headers, paths, and script locations.
<?php
echo $_SERVER['SERVER_NAME'];
echo $_SERVER['PHP_SELF'];
echo $_SERVER['HTTP_HOST'];
?>

PHP $_REQUEST

collect data after submitting a form by GET or POST Method.  

PHP $GLOBALS

for access global variables from anywhere in the PHP . it stores all variables in an array called $GLOBALS[index]. The index holds the name of the variable. example
<?php
$a = 5;
$b = 7;

function addition() {
    $GLOBALS['c'] = $GLOBALS['a'] + $GLOBALS['b'];
}
addition();
echo $c;
?>

Wednesday, 10 February 2016

Definitions and use of function

Definitions and use of function.

A function is a group of code which takes one or more parameter/arguments, and after process, give return a value. A function will not execute until we call to the function.

Note: A function name can not a number.

Syntax:

function YourFunctionName( )
{  
    STATEMENTS 1;
    STATEMENTS 2;
    STATEMENTS 3;

}

What is Arguments?

An argument is a variable, which is passed in functions. You can pass many parameter ( or argument) in a function (separate with a comma).

Example: 

function  NameAge ( $name, $age ) 
{
    echo "$name age = $age";
}
in this example, only pass two parameter, like this you also pass more parameter according your request.

What is Default Argument in a function?

If you call the function without argument value, then it takes the default value as this argument.
Example: 

<?php
function  NameAge ( $name, $age=20 ) 
{
    echo "$name age = $age";
}

NameAge ("Rakesh");           // output:  Rakesh age = 20
NameAge ("Rakesh","28");  // output:  Rakesh age = 28

?>

In this Example, $age=20 is  default argument  if we not pass any age, then its take $age=20.

Different  types of functions in PHP.


  1. User defined function
  2. Return value function
  3. Variable function
  4. Anonymous function

User defined function

Normally, all kinds of useful functions built-in PHP library. But if a function not find in PHP library. Then PHP allows you to build your own functions.

Tip:"Give the function a name that reflects  the function work"

<?php
  function myFirstFunction()
 {
    echo "This is My Function";
  }
?>

Return value function 


Return value function, return a value according to argument, with return statement.

<?php
  function addTwoNo($a, $b) {
    $total = $a + $b;
    return $total;
  }
 echo $sum = example(20, 30);
?>

Variable function

PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.

<?php
    $func = "sqrt";
    print $func(7);
?>

Hear we see that PHP are calling a function using a variable, 

Anonymous function

An anonymous function is simply a function with No Name.
An anonymous function has no name so you would define it like this:
<?php
function () {
  return "Hello PHP";
}
?>

Saturday, 6 February 2016

How cursor move in "For Loop"?

How cursor move in "For Loop"?


For Loop execute specific Line/area  again and again, until the certain condition not false.

 The syntax of a for loop is:

 for(initialization; condition; increment/decrement)

for(i=0; i<=10; i++)
{
    Print i;
}


Step by Step For Loop Process


1. Cursor initialize the value i=1;
2. then check the condition (if i<=10) 
3. if condition is true (means i<=10) then , cursor execute next line.
4. after that go to  increment/decrement,
5. in step five, again check condition (if i<=10), means again step 2 until condition (if i<=10) not flase.
6. if condition (if i<=10) flase, cursor jump out the loop.



Flowchart of for loop


Saturday, 30 January 2016

How to Install WAMP Server? Step by Step Process.

How to Install WAMP Server? Step by Step Process.


  1.  Search on Google "Download wamp Server".
  2.  Click on http://www.wampserver.com/en/
  3.  Select version according to your computer specification.
  4.  After download the WAMP Double Click on setup.
  5. After Start dialog box, You have only follow easy step to Install , only click NEXT,NEXT,NEXT,YES,NEXT and FINISH.















PHP is a programming language.

PHP is a programming language.


The PHP means Hypertext Preprocessor (PHP) is a scripting language,  where we develop  dynamic website  interacts with databases.PHP is free and it Download from www.php.net
PHP is a server side programming  language. Therefore, you need a server to run PHP.
  1. LAMP :-(Linux Apache MySQL PHP);
  2. WAMP :-(Windows Apache MySQL PHP);
  3. MAMP :-(MAC Apache MySQL PHP);
  4. XAMPP:-(x-os Apache MySQL PHP Perl); 
For develop and run PHP need  three components to be installed in your computer.
  1. Linux or windows server (Ex:-WAMP)
  2. Code editor  (Ex:-notepad++)
  3. web browser (Ex:- mozilla firefox)