diff --git a/Koterov-php-training/methods_of_classes/index.php b/Koterov-php-training/methods_of_classes/index.php index dc06dc3..004c0d9 100644 --- a/Koterov-php-training/methods_of_classes/index.php +++ b/Koterov-php-training/methods_of_classes/index.php @@ -111,4 +111,26 @@ echo"А теперь - {$objs[0]->getCount()} объекстов.
"; $objs = []; -echo 'Под конец осталось - '. Counter::getCount() .' Объектов.

'; \ No newline at end of file +echo 'Под конец осталось - '. Counter::getCount() .' Объектов.

'; + +// require_once "minmax.php"; + +// $obj = new MinMax(); +// echo $obj->min(43, 18, 5, 61, 23, 10, 56, 36); +// echo '
'; +// echo $obj->max(43, 18, 5, 61, 23); +// echo '

'; + +require_once "minmax_alter.php"; +$obj = new MinMaxAlt(); +echo $obj->min(43, 18, 5, 61, 23, 10, 56, 36); +echo '
'; +echo $obj->max(43, 18, 5, 61, 23); +echo '

'; + +require_once "minmax_static.php"; +echo 'Вызов статического метода __callStatic()

'; +echo MinMaxStat::min(43, 18, 5, 61, 23, 10, 56, 36); +echo '
'; +echo MinMaxStat::max(43, 18, 5, 61, 23); +echo '

'; diff --git a/Koterov-php-training/methods_of_classes/minmax.php b/Koterov-php-training/methods_of_classes/minmax.php new file mode 100644 index 0000000..0480b9a --- /dev/null +++ b/Koterov-php-training/methods_of_classes/minmax.php @@ -0,0 +1,38 @@ +min($arr); + case 'max': + return $this->max($arr); + default: + return null; + } + } + + private function min(array $arr) : mixed { + $result = $arr[0]; + + foreach ($arr as $value) { + if ($value < $result) { + $result = $value; + } + } + return $result; + } + + private function max(array $arr) : mixed { + $result = $arr[0]; + + foreach ($arr as $value) { + if ($value > $result) { + $result = $value; + } + } + return $result; + } +} \ No newline at end of file diff --git a/Koterov-php-training/methods_of_classes/minmax_alter.php b/Koterov-php-training/methods_of_classes/minmax_alter.php new file mode 100644 index 0000000..7d6dfbc --- /dev/null +++ b/Koterov-php-training/methods_of_classes/minmax_alter.php @@ -0,0 +1,17 @@ +