25 lines
715 B
PHP
25 lines
715 B
PHP
<?php
|
|
// Class definition that creates an instance of a class
|
|
class ExampleClass {
|
|
public $exampleVariable; // a variable belonging to the class instance
|
|
|
|
// Constructor function, called when an object is created
|
|
public function __construct($value) {
|
|
$this->exampleVariable = $value; // assigns value to the instance variable
|
|
}
|
|
|
|
// Function that adds two numbers
|
|
public function add($number1, $number2) {
|
|
return $number1 + $number2; // returns the sum
|
|
}
|
|
}
|
|
|
|
// Example function: multiplies two numbers
|
|
function multiply($number1, $number2) {
|
|
return $number1 * $number2; // returns the product
|
|
}
|
|
|
|
// Array example
|
|
$sampleArray = [1, 2, 3, 4, 5]; // array of numbers
|
|
?>
|