This option will reset the home page of this site. Restoring any closed widgets or categories.

Reset

Creating a simple class file using PHP

Here i will just demonstrate how to create simple php scripts using classes.First we should create a CLASS file

<?php class CarCounter{var $cars = 0;var $weightPerCar = 500.0; function add($n = 1){$this->cars = $this->cars + $n;} function totalWeight(){return $this->cars * $this->weightPerCar;}}?>

i named this class file as class.php  Now i am going to create a index page

<?php        include "class.php";        $cars = new CarCounter;         $cars->cars = 5;      print "There are " . $cars->cars . " cars<br />";       $cars->add(10);      print "There are " . $cars->cars . " cars<br />";      print "Total weight = " . $cars->totalWeight() . " kg<br />";       $cars->weightPerCar = 700.0;             print "With the new weight per car, your total weight is now " . $cars->totalWeight() . " kg";      ?>

I named it INDEX.PHP Check the file in server and see what happens

VN:F [1.5.7_846]
Rating: 0.0/10 (0 votes cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)

Related posts:

  1. Creating An Image Using PHP
  2. PHP class simple tutorial
  3. PHP class simple tutorial
  4. Simple XML Reading Using PHP
  5. Loading swf file from another server using crossdomain.xml
  6. Simple Pagination Using PHP Script
  7. Append data to a text file using php

Leave a Reply

Comments (required)

Spam Protected