This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Classes/Objects

Define Objects

Apple
Banana

<?php
// define the class "Fruit"
class Fruit {
  // Properties
  public $name;
  public $color;

  // Methods
  function set_name($name) {
    $this->name = $name;
  }
  function get_name() {
    return $this->name;
  }
}

// add objects to the class
$apple = new Fruit();
$banana = new Fruit();
$apple->set_name('Apple');
$banana->set_name('Banana');

// display objects in the class
echo $apple->get_name();
echo "<br>";
echo $banana->get_name();
?>