articles

Home / DeveloperSection / Articles / PHP Introduction

PHP Introduction

Royce Roy4697 04-Jun-2016

What is PHP? 

PHP is an HTML-embedded scripting language.First version of PHP was developed by Rasmus Lerdorf in 1994.

§  PHP is a recursive acronym for “PHP:Hypertext Preprocessor”. PHP is a programming langauage allows web developers  to create dynamic web pages.

§  PHP is a widely used open source scripting language that is especially suited for web development.It is used to manage dynamic content,session tracking,databases,even built entire e-commerce sites.

§  PHP is a scripting language ,like HTML.That means its code does not need to be compiled.

§  PHP is free .Download it from www.php.net

§  PHP syntax is C-like.

Uses of PHP 

  •   Using PHP you can create,delete,insert,modify within your database.
  •   PHP can send and receive cookies.
  •   PHP can can generate dynamic page.
  •   Using php, you can restrict users to access some pages of your websites.
  •   It can encrypt data
PHP Operator 

PHP supports following types of operator:

·         Arithmetic  Operators

·         Assignment Operators

·         Comparision Operators

·         Increment/Decrement Operators

·         Logical Operators

·         String Operators

·         Array Operators

Arithmetic Operator: 

Let the value of $x = 10  &  $y = 20.Now let’s perform some arithmetic operation:

Operator

Name

Example

Result

 

‘+’

 

Addition

               $x  +   $y

30

‘-’

Subtraction

                $x  -   $y

-10

 

‘*’

Multiplication

                $x  *   $y

200

‘/’

Division

$x  /   $y

2

‘%’

Modulus

$x  %  $y

0

PHP Assignment Operators: 

There are some assignment operators supported by PHP:

Let the value of $x = 10 .Now let’s perform some Assignment operation:

 

Assignment

Also written as

Description

Result

x=y

x=y

The left operand get the value of right operand.

10

x+=y

x=x+y

Addition:$x=10

$x+=100;

echo $x

120

x-=y

x=x-y

Subtraction:$x=10

$x-=100;

echo $x

-90

x*=y

x=x*y

Multiplication:$x=10

$x*=100;

echo $x

1000

x/=y

x=x/y

Division:$x=10

$x/=5;

echo $x

2

x%=y

x=x%y

Modulus:$x=15

$x%=4;

echo $x

3

 

 PHP Comparision Operators:

PHP Comparision operators are used to compare two values.these value can be number or string.

Operator

Name

Example

Result

==

Equal

$a==$b

Returns true if $a is equal to $b.

===

Identical

$a===$b

Returns true,if $a is equal to $b along with same data type.

!=

Not equal

$a!=$b

Returns true if $a is not equal to $b

<> 

Not equal

$a<>$b

Returns true if $a is not equal to $b

!==

Not identical

$a!==$b

Returns true,if $a is not equal to $b and not of same data type.

> 

Greater than

$a>$b

Returns true if $a is greater than to $b

< 

Less than

$a<$b

Returns true if $a is less than  to $b

>=

Greater than or equal

$a>=$b

Returns true if $a is greater or equal to $b

<=

Less than or equal

$a<=$b

Returns true if $a is less or equal to $b

PHP Increment/Decrement Operators:

Let the value of $a=10

Operator

Name

Description

Result

++$a

Pre-increment

Increment $a by 1, than return the value

11

$a++

Post-increment

Return value,than increment by 1

10

--$a

Pre-decrement

Decrement by 1,than return the value

9

$a--

Post-decrement

Return value,than decrement

10

 

PHP Logical Operator

These operators are used to combine conditional statements.

Operator

Name

Example

Result

and

And

$a and $y

True if both $a and $b are true

or

Or

$a or $b

True if either $a or $b is true

xor

Xor

$a xor $b

True if either $a or $b is true but not both

&&

And

$a && $b

True if both $a and $b are true

||

Or

$a || $b

True if either $a or $b is true

!

Not

$a!

True if $a is not true

 

PHP string Operators

These operators are used specially in strings.

Operator

Name

Example

Result

.

Concatenation

$a.$b

Concatination of $a and $b

.=

Concatination assignment

$a.=$b

Append $b to $a

 PHP Array Operators

These array operators are used to compare.

Operator

Name

Result

Example

+

Union

$a + $b

Union of $a and $b

==

Equality

$a  == $b

Returns true if $a and $b have same key/value

 

===

Identity

$a===$b

Returns true if $a and $b have same key/value

In same order and same type

!=

Inequality

$a != $b

Returns true if $a is not equal to $b

 

<> 

Inequality

$a <> $b

Returns true if $a is not equal to $b

 

!==

Non-identity

$a !== $b

Returns true if $a is not identical  to $b

 


Updated 28-Mar-2020

Leave Comment

Comments

Liked By