Sunday, 23 October 2016

Class in PHP | How create classes in PHP

Classes in PHP

Php Classes.Classes in Php is a new concept like C++.It covers the OOPs concept in PHP.OOPs stands for Object Oriented Programming.you can create classes in PHP like c++ with functions.

To do this:

<?php
class abc
{
function add1()
{
$a=10;
$b=20;
$c=$a+$b;
echo $c;
}
}
$obj=new abc;
$obj->add1();
?>

In the above PHP class example, we create a class with name "abc" also create function name "add1"
we declare two variable a and b and assign them value.Add them and assign the result to another variable c and show the result with echo command.

After this, we create an object of the class and call the function using that object. 

We can add multiple classes and functions in PHP.

<?php
class abc
{
function add1()
{
$a=10;
$b=20;
$c=$a+$b;
echo $c;
}
function mul()
{
$a=10;
$b=20;
$c=$a*$b;
echo $c;
}
}
$obj=new abc;
$obj->add1();
echo "</br>";
$obj->mul();

?>

PHP Class



Php Class
Php Class



No comments:

Post a Comment

Leave a Reply!