Php
Online Compiler
https://onecompiler.com/php/3yhfgsuh3
Print a line
echo"Welcome to BSSE";
Variable Declaration
 $num=5;
 echo $num;
String Concatenation
 $num=5;
 echo "Number is:",$num;
Comment
 Single line
//echo "Number is:",$num;
 Multi line
/*echo "Number is:",$num; */
PHP ─ Variable Types
 Integers: are whole numbers, without a decimal point, like
4195.
$int_var = 12345;
 Doubles: are floating-point numbers, like 3.14159 or 49.1.
$many = 2.2888800;
 Booleans: have only two possible values either true or false.
 NULL: is a special type that only has one value: NULL.
$my_var = null;
 Strings: are sequences of characters, like 'PHP supports
string operations.
$string_1 = "This is a string in double quotes";
7
PHP ─ Variable Types
 Arrays: are named and indexed collections of other values.
 Objects: are instances of programmer-defined classes,
which can package up both other kinds of values and
functions that are specific to the class.
8
PHP – Variables
 Local variables
<?
$x = 4;
function assignx () {
$x = 0;
print "$x inside function is $x. ";
}
assignx();
print "$x outside of function is $x. ";
?>
9
PHP – Variables
 Function parameters
<?
// multiply a value by 10 and return it to the caller
function multiply ($value) {
$value = $value * 10;
return $value;
}
$retval = multiply (10);
Print "Return value is $retvaln";
?>
10
PHP – Variables
 Global variables
<?
$somevar = 15;
function addit() {
GLOBAL $somevar;
$somevar++;
print "Somevar is $somevar";
}
addit();
?>
11
PHP – Variables
 Static variables
<?
function keep_track() {
STATIC $count = 0;
$count++;
print $count;
print " ";
}
keep_track();
keep_track();
keep_track();
?>
12
PHP ─ Operator Type
 Arithmetic Operators
<?php
$a = 42;
$b = 20;
$c = $a + $b;
echo "Addition Operation Result: $c ";
$c = $a - $b;
echo "Subtraction Operation Result: $c ";
$c = $a * $b;
echo "Multiplication Operation Result: $c ";
$c = $a / $b;
echo "Division Operation Result: $c ";
$c = $a % $b;
echo "Modulus Operation Result: $c ";
$c = $a++;
echo "Increment Operation Result: $c ";
$c = $a--;
echo "Decrement Operation Result: $c ";
?> 13
PHP ─ Operator Type
 Comparison Operators
<?php
$a = 42;
$b = 20;
if( $a == $b ){
echo "TEST1 : a is equal to b";
}else{
echo "TEST1 : a is not equal to b";
}
if( $a > $b ){
echo "TEST2 : a is greater than b";
}else{
echo "TEST2 : a is not greater than b";
}
if( $a < $b ){
echo "TEST3 : a is less than b";
}else{
echo "TEST3 : a is not less than b";
} 14
PHP ─ Operator Type
 Comparison Operators
if( $a != $b ){
echo "TEST4 : a is not equal to b";
}else{
echo "TEST4 : a is equal to b";
}
if( $a >= $b ){
echo "TEST5 : a is either greater than or equal to b";
}else{
echo "TEST5 : a is neither greater than nor equal to b";
}
if( $a <= $b ){
echo "TEST6 : a is either less than or equal to b";
}else{
echo "TEST6 : a is neither less than nor equal to b";
}
?>
15
PHP ─ Operator Type
 Assignment Operators
<?php
$a = 42;
$b = 20;
$c = $a + $b; /* Assignment operator */
echo "Addition Operation Result: $c <br/>";
$c += $a; /* c value was 42 + 20 = 62 */
echo "Add AND Assignment Operation Result: $c <br/>";
$c -= $a; /* c value was 42 + 20 + 42 = 104 */
echo "Subtract AND Assignment Operation Result: $c <br/>";
$c *= $a; /* c value was 104 - 42 = 62 */
echo "Multiply AND Assignment Operation Result: $c <br/>";
$c /= $a; /* c value was 62 * 42 = 2604 */
16
PHP ─ Operator Type
 Assignment Operators
echo "Division AND Assignment Operation Result: $c <br/>";
$c %= $a; /* c value was 2604/42 = 62*/
echo "Modulus AND Assignment Operation Result: $c <br/>";
?>
17
PHP ─ Decision Making
 If else
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
18
PHP ─ Decision Making
 Switch
<?php
$d=date("D");
switch ($d)
{
case "Mon":
echo "Today is Monday";
break;
case "Tue":
echo "Today is Tuesday";
break;
case "Wed":
echo "Today is Wednesday";
break;
case "Thu":
echo "Today is Thursday";
break;
19
PHP ─ Decision Making
 Switch
case "Fri":
echo "Today is Friday";
break;
case "Sat":
echo "Today is Saturday";
break;
case "Sun":
echo "Today is Sunday";
break;
default:
echo "Wonder which day is this ?";
}
?>
20
PHP while Loop
 The while loop - Loops through a block of code as long as the specified
condition is true.
 while (condition is true) {
code to be executed;
}
 <?php
$x = 0;
while($x <= 100) {
echo "The number is: $x <br>";
$x+=10;
}
?>
21
PHP do while Loop
 The do...while loop will always execute the block of code once, it will then
check the condition, and repeat the loop while the specified condition is
true.
 do {
code to be executed;
} while (condition is true);
 <?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
22
PHP for Loop
 The for loop is used when you know in advance how many times the script
should run.
 for (init counter; test counter; increment counter) {
code to be executed for each iteration;
}
 <?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
23
PHP foreach Loop
 The foreach loop works only on arrays, and is used to loop through each
key/value pair in an array.
 foreach ($array as $value) {
code to be executed;
}
 <?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
24
PHP Built-in Functions
 PHP has over 1000 built-in functions that can be called directly, from within
a script, to perform a specific task.
25
PHP User Defined Functions
 Besides the built-in PHP functions, it is possible to create your own
functions.
 A function is a block of statements that can be used repeatedly in a program.
 A function will not execute automatically when a page loads.
 A function will be executed by a call to the function.
26
Create a User Defined Function in PHP
 function functionName() {
code to be executed;
}
 <?php
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
?>
27
PHP Function Arguments
 <?php
function familyName($fname) {
echo "$fname Refsnes.<br>";
}
familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>
28
PHP Functions - Returning values
 <?php declare(strict_types=1); // strict requirement
function sum(int $x, int $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>
29
PHP String Functions
 The PHP strlen() function returns the length of a string.
 echo strlen("Hello world!"); // outputs 12
 The PHP str_word_count() function counts the number of words in a
string.
 echo str_word_count("Hello world!"); // outputs 2
 The PHP strrev() function reverses a string.
 echo strrev("Hello world!"); // outputs !dlrow olleH
 The PHP strpos() function searches for a specific text within a string. If
a match is found, the function returns the character position of the first
match. If no match is found, it will return FALSE.
 echo strpos("Hello world!", "world"); // outputs 6
 The PHP str_replace() function replaces some characters with some
other characters in a string.
 echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
30
PHPArrays
PHP array is an ordered map (contains value on the basis of key). It is
used to hold multiple values of similar type in a single variable.
PHPArray Types
There are 3 types of array in PHP.
 Indexed Array
 Associative Array
 Multidimensional Array
PHP Indexed Array
PHP index is represented by number which starts from 0. We can store
number, string and object in the PHP array. All PHP array elements are
assigned to an index number by default.
<?php
$season=array("summer","winter","spring","autumn");
echo "Season are: $season[0], $season[1], $season[2] and $season[3]";
?>
PHPAssociative Array
We can associate name with each array elements in PHP using => symbol.
<?php
$salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000")
;
echo "Sonoo salary: ".$salary["Sonoo"]."<br/>";
echo "John salary: ".$salary["John"]."<br/>";
echo "Kartik salary: ".$salary["Kartik"]."<br/>";
?>
PHP Multidimensional Array
PHP multidimensional array is also known as array of arrays. It allows you
to store tabular data in an array. PHP multidimensional array can be
represented in the form of matrix which is represented by row *
column.
<?php
$emp = array (
array(1,"sonoo",400000),
array(2,"john",500000),
array(3,"rahul",300000) );
for ($row = 0; $row < 3; $row++) {
for ($col = 0; $col < 3; $col++) {
echo $emp[$row][$col]." "; }
echo "<br/>";
}
?>
PHP Math
 PHP Math: abs() function
The abs() function returns absolute value of given number. It returns
an integer value but if you pass floating point value, it returns a float
value.
 PHP Math: ceil() function
The ceil() function rounds fractions up.
 PHP Math: floor() function
The floor() function rounds fractions down.
 PHP Math: sqrt() function
The sqrt() function returns square root of given argument.
 PHP Math: decbin() function
The decbin() function converts decimal number into binary. It returns
binary number as a string.
PHP Math
Function Description
acos() It is used to return the arc
cosine of a number.
acosh() It is used to return the
inverse hyperbolic cosine of
a number.
tan() It is used to return the
tangent of a number.
tanh() It is used to return the
hyperbolic tangent of a
number.
atan() It is used to return the arc
tangent of a number in
radians.
atan2() It is used to return the arc
tangent of two variables x
and y.
PHP Math
Function Description
atanh() It is used to return the
inverse hyperbolic tangent
of a number.
base_convert() It is used to convert a
number from one number
base to another.
bindec() It is used to convert a binary
number to a decimal
number.
ceil() It is used to find round a
number up to the nearest
integer.
pi() It returns the approximation
value of PI.
Object-Oriented Programming / OOPs
 It is a form of programming concept where everything is considered on an
object, and then we implement software with the help of using these
different objects.
 For example, in a school, all students, teaching staff, administrative staff,
etc., can be considered objects of a certain type called school.
Class
 A class is an entity that determines how an object will behave and what the
object will contain. In other words, it is a blueprint or a set of instruction to
build a specific type of object.
 In PHP, declare a class using the class keyword, followed by the name of
the class and a set of curly braces ({}).
<?php
class MyClass
{
// Class properties and methods go here
}
?>
Object
 A class defines an individual instance of the data structure. We define a
class once and then make many objects that belong to it. Objects are also
known as an instance.
<?php
class demo
{
private $a= "hello javatpoint";
public function display()
{
echo $this->a;
}
}
$obj = new demo();
$obj->display();
?>
ABSTRACT CLASS
 An abstract class is a mix between an interface and a class. It can be define
functionality as well as interface.
 Classes extending an abstract class must implement all of the abstract
methods defined in the abstract class.
 An abstract class is declared the same way as classes with the addition of
the 'abstract' keyword.
abstract class MyAbstract
{
//Methods
}
//And is attached to a class using the extends keyword.
class Myclass extends MyAbstract
{
//class methods
}
Abstraction in PHP
 Data Abstraction is the most important features of any OOPS
programming language.
 It shows only useful information, remaining are hidden form the end
user.
 Abstraction is the any representation of data in which the
implementation details are hidden (abstracted).
Define Class in PHP
<!DOCTYPE html>
<html lang = " en ">
<head> <title> PHP </title>
</head>
<body>
<? Php
class cars {
// Properties
var $name;
var $color;
// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
function set_color($color) {
$this->color = $color;
}
function get_color() {
return $this->color;
} }
Define Class in PHP
$BMW = new cars();
$audi = new cars();
$volvo = new cars();
$BMW->set_name('BMW ');
$BMW->set_color('red');
$audi->set_name('audi ');
$audi->set_color('blue');
$volvo->set_name('volvo ');
$volvo->set_color('black');
echo $BMW->get_name();
echo " --> ";
echo $BMW->get_color();
echo "<br>";
echo $audi->get_name();
echo " --> ";
echo $audi->get_color();
echo "<br>";
echo $volvo->get_name();
echo " --> ";
echo $volvo->get_color();
?>
</body>
</html>
Constructors
These are a special types of functions that are automatically called
whenever an object is created. These function are created by using the
_construct ( ) keyword.
function __construct( $ parameter 1, $ parameter 2 ) {
$this->name = $ parameter 1;
$this->state = $ parameter 2;
}
Inheritance
It is a concept of accessing the features of one class from another class. If
we inherit the class features into another class, we can access both class
properties. We can extends the features of a class by using 'extends'
keyword.
It supports the concept of hierarchical classification.Inheritance has
three types, single, multiple and multilevel Inheritance.
PHP supports only single inheritance, where only one class can
be derived from single parent class.
We can simulate multiple inheritance by using interfaces.
Inheritance
<?php
class a
{
function fun1()
{
echo "javatpoint";
}
}
class b extends a
{
function fun2()
{
echo "SSSIT";
}
}
$obj= new b();
$obj->fun1();
?>
Access Specifiers in PHP
 There are 3 types of Access Specifiers available in PHP, Public, Private and
Protected.
 Public - class members with this access modifier will be publicly accessible
from anywhere, even from outside the scope of the class.
 Private - class members with this keyword will be accessed within the class
itself. It protects members from outside class access with the reference of the
class instance.
 Protected - same as private, except by allowing subclasses to access protected
superclass members.
Access Specifiers in PHP
<?php
classJavatpoint
{
public $name="Ajeet";
protected $profile="HR";
private $salary=5000000;
public function show()
{
echo "Welcome : ".$this->name."<br/>";
echo "Profile : ".$this->profile."<br/>";
echo "Salary : ".$this->salary."<br/>";
} }
classchilds extends Javatpoint
{
public function show1()
{
echo "Welcome : ".$this->name."<br/>";
echo "Profile : ".$this->profile."<br/>";
echo "Salary : ".$this->salary."<br/>";
}
}
$obj= new childs;
$obj->show1();
?>
Encapsulation in PHP
 Encapsulation is a concept where we encapsulate all the data and
member functions together to form an object.
 Wrapping up data member and method together into a single unit
is called Encapsulation.
 Encapsulation also allows a class to change its internal
implementation without hurting the overall functioning of the
system.
 Binding the data with the code that manipulates it.
 It keeps the data and the code safe from external interference.
Interface
 An interface is similar to a class except that it cannot contain code.
 An interface can define method names and arguments, but not the
contents of the methods.
 Any classes implementing an interface must implement all methods
defined by the interface.
 A class can implement multiple interfaces.
 An interface is declared using the "interface" keyword.
 Interfaces can't maintain Non-abstract methods.
Interface
<?php
interface a
{
public function dis1();
}
interface b
{
public function dis2();
}
class demo implements a,b
{
public function dis1()
{
echo "method 1...";
}
public function dis2()
{
echo "method2...";
}
}
$obj= new demo();
$obj->dis1();
$obj->dis2();
?>

Web Technology_10.ppt

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
    String Concatenation  $num=5; echo "Number is:",$num;
  • 6.
    Comment  Single line //echo"Number is:",$num;  Multi line /*echo "Number is:",$num; */
  • 7.
    PHP ─ VariableTypes  Integers: are whole numbers, without a decimal point, like 4195. $int_var = 12345;  Doubles: are floating-point numbers, like 3.14159 or 49.1. $many = 2.2888800;  Booleans: have only two possible values either true or false.  NULL: is a special type that only has one value: NULL. $my_var = null;  Strings: are sequences of characters, like 'PHP supports string operations. $string_1 = "This is a string in double quotes"; 7
  • 8.
    PHP ─ VariableTypes  Arrays: are named and indexed collections of other values.  Objects: are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class. 8
  • 9.
    PHP – Variables Local variables <? $x = 4; function assignx () { $x = 0; print "$x inside function is $x. "; } assignx(); print "$x outside of function is $x. "; ?> 9
  • 10.
    PHP – Variables Function parameters <? // multiply a value by 10 and return it to the caller function multiply ($value) { $value = $value * 10; return $value; } $retval = multiply (10); Print "Return value is $retvaln"; ?> 10
  • 11.
    PHP – Variables Global variables <? $somevar = 15; function addit() { GLOBAL $somevar; $somevar++; print "Somevar is $somevar"; } addit(); ?> 11
  • 12.
    PHP – Variables Static variables <? function keep_track() { STATIC $count = 0; $count++; print $count; print " "; } keep_track(); keep_track(); keep_track(); ?> 12
  • 13.
    PHP ─ OperatorType  Arithmetic Operators <?php $a = 42; $b = 20; $c = $a + $b; echo "Addition Operation Result: $c "; $c = $a - $b; echo "Subtraction Operation Result: $c "; $c = $a * $b; echo "Multiplication Operation Result: $c "; $c = $a / $b; echo "Division Operation Result: $c "; $c = $a % $b; echo "Modulus Operation Result: $c "; $c = $a++; echo "Increment Operation Result: $c "; $c = $a--; echo "Decrement Operation Result: $c "; ?> 13
  • 14.
    PHP ─ OperatorType  Comparison Operators <?php $a = 42; $b = 20; if( $a == $b ){ echo "TEST1 : a is equal to b"; }else{ echo "TEST1 : a is not equal to b"; } if( $a > $b ){ echo "TEST2 : a is greater than b"; }else{ echo "TEST2 : a is not greater than b"; } if( $a < $b ){ echo "TEST3 : a is less than b"; }else{ echo "TEST3 : a is not less than b"; } 14
  • 15.
    PHP ─ OperatorType  Comparison Operators if( $a != $b ){ echo "TEST4 : a is not equal to b"; }else{ echo "TEST4 : a is equal to b"; } if( $a >= $b ){ echo "TEST5 : a is either greater than or equal to b"; }else{ echo "TEST5 : a is neither greater than nor equal to b"; } if( $a <= $b ){ echo "TEST6 : a is either less than or equal to b"; }else{ echo "TEST6 : a is neither less than nor equal to b"; } ?> 15
  • 16.
    PHP ─ OperatorType  Assignment Operators <?php $a = 42; $b = 20; $c = $a + $b; /* Assignment operator */ echo "Addition Operation Result: $c <br/>"; $c += $a; /* c value was 42 + 20 = 62 */ echo "Add AND Assignment Operation Result: $c <br/>"; $c -= $a; /* c value was 42 + 20 + 42 = 104 */ echo "Subtract AND Assignment Operation Result: $c <br/>"; $c *= $a; /* c value was 104 - 42 = 62 */ echo "Multiply AND Assignment Operation Result: $c <br/>"; $c /= $a; /* c value was 62 * 42 = 2604 */ 16
  • 17.
    PHP ─ OperatorType  Assignment Operators echo "Division AND Assignment Operation Result: $c <br/>"; $c %= $a; /* c value was 2604/42 = 62*/ echo "Modulus AND Assignment Operation Result: $c <br/>"; ?> 17
  • 18.
    PHP ─ DecisionMaking  If else if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; else code to be executed if condition is false; <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; elseif ($d=="Sun") echo "Have a nice Sunday!"; else echo "Have a nice day!"; ?> 18
  • 19.
    PHP ─ DecisionMaking  Switch <?php $d=date("D"); switch ($d) { case "Mon": echo "Today is Monday"; break; case "Tue": echo "Today is Tuesday"; break; case "Wed": echo "Today is Wednesday"; break; case "Thu": echo "Today is Thursday"; break; 19
  • 20.
    PHP ─ DecisionMaking  Switch case "Fri": echo "Today is Friday"; break; case "Sat": echo "Today is Saturday"; break; case "Sun": echo "Today is Sunday"; break; default: echo "Wonder which day is this ?"; } ?> 20
  • 21.
    PHP while Loop The while loop - Loops through a block of code as long as the specified condition is true.  while (condition is true) { code to be executed; }  <?php $x = 0; while($x <= 100) { echo "The number is: $x <br>"; $x+=10; } ?> 21
  • 22.
    PHP do whileLoop  The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.  do { code to be executed; } while (condition is true);  <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?> 22
  • 23.
    PHP for Loop The for loop is used when you know in advance how many times the script should run.  for (init counter; test counter; increment counter) { code to be executed for each iteration; }  <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>"; } ?> 23
  • 24.
    PHP foreach Loop The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.  foreach ($array as $value) { code to be executed; }  <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?> 24
  • 25.
    PHP Built-in Functions PHP has over 1000 built-in functions that can be called directly, from within a script, to perform a specific task. 25
  • 26.
    PHP User DefinedFunctions  Besides the built-in PHP functions, it is possible to create your own functions.  A function is a block of statements that can be used repeatedly in a program.  A function will not execute automatically when a page loads.  A function will be executed by a call to the function. 26
  • 27.
    Create a UserDefined Function in PHP  function functionName() { code to be executed; }  <?php function writeMsg() { echo "Hello world!"; } writeMsg(); // call the function ?> 27
  • 28.
    PHP Function Arguments <?php function familyName($fname) { echo "$fname Refsnes.<br>"; } familyName("Jani"); familyName("Hege"); familyName("Stale"); familyName("Kai Jim"); familyName("Borge"); ?> 28
  • 29.
    PHP Functions -Returning values  <?php declare(strict_types=1); // strict requirement function sum(int $x, int $y) { $z = $x + $y; return $z; } echo "5 + 10 = " . sum(5, 10) . "<br>"; echo "7 + 13 = " . sum(7, 13) . "<br>"; echo "2 + 4 = " . sum(2, 4); ?> 29
  • 30.
    PHP String Functions The PHP strlen() function returns the length of a string.  echo strlen("Hello world!"); // outputs 12  The PHP str_word_count() function counts the number of words in a string.  echo str_word_count("Hello world!"); // outputs 2  The PHP strrev() function reverses a string.  echo strrev("Hello world!"); // outputs !dlrow olleH  The PHP strpos() function searches for a specific text within a string. If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.  echo strpos("Hello world!", "world"); // outputs 6  The PHP str_replace() function replaces some characters with some other characters in a string.  echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly! 30
  • 31.
    PHPArrays PHP array isan ordered map (contains value on the basis of key). It is used to hold multiple values of similar type in a single variable.
  • 32.
    PHPArray Types There are3 types of array in PHP.  Indexed Array  Associative Array  Multidimensional Array
  • 33.
    PHP Indexed Array PHPindex is represented by number which starts from 0. We can store number, string and object in the PHP array. All PHP array elements are assigned to an index number by default. <?php $season=array("summer","winter","spring","autumn"); echo "Season are: $season[0], $season[1], $season[2] and $season[3]"; ?>
  • 34.
    PHPAssociative Array We canassociate name with each array elements in PHP using => symbol. <?php $salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000") ; echo "Sonoo salary: ".$salary["Sonoo"]."<br/>"; echo "John salary: ".$salary["John"]."<br/>"; echo "Kartik salary: ".$salary["Kartik"]."<br/>"; ?>
  • 35.
    PHP Multidimensional Array PHPmultidimensional array is also known as array of arrays. It allows you to store tabular data in an array. PHP multidimensional array can be represented in the form of matrix which is represented by row * column. <?php $emp = array ( array(1,"sonoo",400000), array(2,"john",500000), array(3,"rahul",300000) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col]." "; } echo "<br/>"; } ?>
  • 36.
    PHP Math  PHPMath: abs() function The abs() function returns absolute value of given number. It returns an integer value but if you pass floating point value, it returns a float value.  PHP Math: ceil() function The ceil() function rounds fractions up.  PHP Math: floor() function The floor() function rounds fractions down.  PHP Math: sqrt() function The sqrt() function returns square root of given argument.  PHP Math: decbin() function The decbin() function converts decimal number into binary. It returns binary number as a string.
  • 37.
    PHP Math Function Description acos()It is used to return the arc cosine of a number. acosh() It is used to return the inverse hyperbolic cosine of a number. tan() It is used to return the tangent of a number. tanh() It is used to return the hyperbolic tangent of a number. atan() It is used to return the arc tangent of a number in radians. atan2() It is used to return the arc tangent of two variables x and y.
  • 38.
    PHP Math Function Description atanh()It is used to return the inverse hyperbolic tangent of a number. base_convert() It is used to convert a number from one number base to another. bindec() It is used to convert a binary number to a decimal number. ceil() It is used to find round a number up to the nearest integer. pi() It returns the approximation value of PI.
  • 39.
    Object-Oriented Programming /OOPs  It is a form of programming concept where everything is considered on an object, and then we implement software with the help of using these different objects.  For example, in a school, all students, teaching staff, administrative staff, etc., can be considered objects of a certain type called school.
  • 40.
    Class  A classis an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object.  In PHP, declare a class using the class keyword, followed by the name of the class and a set of curly braces ({}). <?php class MyClass { // Class properties and methods go here } ?>
  • 41.
    Object  A classdefines an individual instance of the data structure. We define a class once and then make many objects that belong to it. Objects are also known as an instance. <?php class demo { private $a= "hello javatpoint"; public function display() { echo $this->a; } } $obj = new demo(); $obj->display(); ?>
  • 42.
    ABSTRACT CLASS  Anabstract class is a mix between an interface and a class. It can be define functionality as well as interface.  Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.  An abstract class is declared the same way as classes with the addition of the 'abstract' keyword. abstract class MyAbstract { //Methods } //And is attached to a class using the extends keyword. class Myclass extends MyAbstract { //class methods }
  • 43.
    Abstraction in PHP Data Abstraction is the most important features of any OOPS programming language.  It shows only useful information, remaining are hidden form the end user.  Abstraction is the any representation of data in which the implementation details are hidden (abstracted).
  • 44.
    Define Class inPHP <!DOCTYPE html> <html lang = " en "> <head> <title> PHP </title> </head> <body> <? Php class cars { // Properties var $name; var $color; // Methods function set_name($name) { $this->name = $name; } function get_name() { return $this->name; } function set_color($color) { $this->color = $color; } function get_color() { return $this->color; } }
  • 45.
    Define Class inPHP $BMW = new cars(); $audi = new cars(); $volvo = new cars(); $BMW->set_name('BMW '); $BMW->set_color('red'); $audi->set_name('audi '); $audi->set_color('blue'); $volvo->set_name('volvo '); $volvo->set_color('black'); echo $BMW->get_name(); echo " --> "; echo $BMW->get_color(); echo "<br>"; echo $audi->get_name(); echo " --> "; echo $audi->get_color(); echo "<br>"; echo $volvo->get_name(); echo " --> "; echo $volvo->get_color(); ?> </body> </html>
  • 46.
    Constructors These are aspecial types of functions that are automatically called whenever an object is created. These function are created by using the _construct ( ) keyword. function __construct( $ parameter 1, $ parameter 2 ) { $this->name = $ parameter 1; $this->state = $ parameter 2; }
  • 47.
    Inheritance It is aconcept of accessing the features of one class from another class. If we inherit the class features into another class, we can access both class properties. We can extends the features of a class by using 'extends' keyword. It supports the concept of hierarchical classification.Inheritance has three types, single, multiple and multilevel Inheritance. PHP supports only single inheritance, where only one class can be derived from single parent class. We can simulate multiple inheritance by using interfaces.
  • 48.
    Inheritance <?php class a { function fun1() { echo"javatpoint"; } } class b extends a { function fun2() { echo "SSSIT"; } } $obj= new b(); $obj->fun1(); ?>
  • 49.
    Access Specifiers inPHP  There are 3 types of Access Specifiers available in PHP, Public, Private and Protected.  Public - class members with this access modifier will be publicly accessible from anywhere, even from outside the scope of the class.  Private - class members with this keyword will be accessed within the class itself. It protects members from outside class access with the reference of the class instance.  Protected - same as private, except by allowing subclasses to access protected superclass members.
  • 50.
    Access Specifiers inPHP <?php classJavatpoint { public $name="Ajeet"; protected $profile="HR"; private $salary=5000000; public function show() { echo "Welcome : ".$this->name."<br/>"; echo "Profile : ".$this->profile."<br/>"; echo "Salary : ".$this->salary."<br/>"; } } classchilds extends Javatpoint { public function show1() { echo "Welcome : ".$this->name."<br/>"; echo "Profile : ".$this->profile."<br/>"; echo "Salary : ".$this->salary."<br/>"; } } $obj= new childs; $obj->show1(); ?>
  • 51.
    Encapsulation in PHP Encapsulation is a concept where we encapsulate all the data and member functions together to form an object.  Wrapping up data member and method together into a single unit is called Encapsulation.  Encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system.  Binding the data with the code that manipulates it.  It keeps the data and the code safe from external interference.
  • 52.
    Interface  An interfaceis similar to a class except that it cannot contain code.  An interface can define method names and arguments, but not the contents of the methods.  Any classes implementing an interface must implement all methods defined by the interface.  A class can implement multiple interfaces.  An interface is declared using the "interface" keyword.  Interfaces can't maintain Non-abstract methods.
  • 53.
    Interface <?php interface a { public functiondis1(); } interface b { public function dis2(); } class demo implements a,b { public function dis1() { echo "method 1..."; } public function dis2() { echo "method2..."; } } $obj= new demo(); $obj->dis1(); $obj->dis2(); ?>