-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleton.php
More file actions
31 lines (26 loc) · 761 Bytes
/
singleton.php
File metadata and controls
31 lines (26 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
class MathFunctions {
private static $instance;
private static $coefArray;
private static $powerArray;
private function __construct() {
}
public static function getInstance($coefArray, $powerArray) {
self::$coefArray = $coefArray;
self::$powerArray = $powerArray;
if (!self::$instance) {
self::$instance = new MathFunctions();
}
return self::$instance;
}
public function getY($x) {
$result = 0;
for ($i = 0; $i <= count(self::$coefArray); $i++) {
$result += self::$coefArray[$i]*pow($x, self::$powerArray[$i]);
}
return $result;
}
}
$math = MathFunctions::getInstance([1, 2], [0, 1]);
echo $math->getY(3);
echo "<br>";