Wednesday, 22 June 2016

What is Operator?

What is PHP Operator?

Operators (its a symbol), which perform operations on variables. example $A + $b = $C. Here "$A" and "$B" are called variables(operands)  But "+" is called Operator.

PHP supports following type of operators.
  1. Arithmetic operators
  2. Assignment operators
  3. Comparison operators
  4. Increment/Decrement operators
  5. Logical operators

Arithmetic operators

In PHP Arithmetic operators are used in numeric values. (Ex- 2+5=7)

Operator Name Example Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y Result of raising $x to the $y'th power


PHP Assignment Operators

PHP assignment operators assign to the value to a variable. (Ex- $x=5, Left operand set to the value on the right. )
Assignment Same as... Description
x = y x = y The left operand gets set to the value of the expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus


PHP Comparison Operators

According to name comparison operators used to compare two values. (Ex- $x == $y)
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y

Increment / Decrement Operators

Increment(++) Operators increases integer one(1) at value, and Decrement (--) Operators Decreases integer one(1) at value
Operator Name Description
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one

Logical Operators

Combine conditional statements (Ex-  if($x == 10 and $y == 50))
Operator Name Example Result
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true

Saturday, 18 June 2016

PHP Data Types

PHP Data Types


Variables can store data of different types, in PHP we do not need define the type of variable, its define automatic at run time.

If we assign  string in a variable, then it becomes a string.
$value="Hello PHP"; // String

Later if we assign an integer value, the variable becomes an integer variable.
$value=10; // integer


 PHP has eight data types:-


Scalar types:
1). Boolean ( It can be either TRUE or FALSE. )
2). Integer (An integer is a "number of set:  n = {...,-3, -2, -1, 0, 1, 2,3, ...}. )
3). Float ( Floating-point number,)
4). String    (Group of characters, like "Hello PHP".)

Compound types:
5). Array (An array is a group of values in one single variable)
6). Object (An object stores data and  code,  its store  information about  how to process that data.)

Special types:
7). Resource ( Holding a reference to an external resource.)

8). NULL (it is a variable that has no value assigned to it)

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)