Last active
February 22, 2018 18:26
-
-
Save Sentinel17/109c9eb48d5ecb3c71f7dacd1e6dad2c to your computer and use it in GitHub Desktop.
Домашнее задание №7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Функции --> | |
<?php | |
function square($a){ | |
return $a * $a; | |
} | |
echo 'Квадрат равен: '.square(7).'<br>'; | |
?> | |
<?php | |
function sum($a, $b){ | |
return $a + $b; | |
} | |
echo 'Сумма равна: '.sum(73, 28).'<br>'; | |
?> | |
<?php | |
function calc($a, $b, $c){ | |
return ($a - $b) / $c; | |
} | |
echo 'Результат: '.calc(30, 15, 3).'<br>'; | |
?> | |
<?php | |
function day($day){ | |
$week = [1=>'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье']; | |
return $week[$day]; | |
} | |
echo 'День недели: '.day(3).'<br>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ООП Construct --> | |
<?php | |
class Worker | |
{ | |
private $name; | |
private $age; | |
private $salary; | |
public function __construct($name, $age, $salary) | |
{ | |
$this->name = $name; | |
$this->age = $age; | |
$this->salary = $salary; | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
public function getAge() | |
{ | |
return $this->age; | |
} | |
public function getSalary() | |
{ | |
return $this->salary; | |
} | |
} | |
$worker = new Worker('Дима', 25, 1000); | |
echo $worker->getAge() * $worker->getSalary(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ООП Private --> | |
<?php | |
class Worker | |
{ | |
private $name; | |
private $age; | |
private $salary; | |
public function getName() | |
{ | |
return $this->name; | |
} | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
public function getAge() | |
{ | |
return $this->age; | |
} | |
public function setAge($age) | |
{ | |
if ($this->checkAge($age)){ | |
$this->age = $age; | |
} | |
} | |
private function checkAge($age) | |
{ | |
if ($age < 100){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
public function getSalary() | |
{ | |
return $this->salary; | |
} | |
public function setSalary($salary) | |
{ | |
$this->salary = $salary; | |
} | |
} | |
$workerOne = new Worker(); | |
$workerOne->setName('Иван'); | |
$workerOne->setAge(25); | |
$workerOne->setSalary(1000); | |
$workerTwo = new Worker(); | |
$workerTwo->setName('Вася'); | |
$workerTwo->setAge(26); | |
$workerTwo->setSalary(2000); | |
echo $workerOne->getSalary() + $workerTwo->getSalary().'<br>'; | |
echo $workerOne->getAge() + $workerTwo->getAge().'<br>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ООП Public --> | |
<?php | |
class Worker | |
{ | |
public $name; | |
Public $age; | |
public $salary; | |
} | |
$workerOne = new Worker(); | |
$workerOne->name = 'Иван'; | |
$workerOne->age = 25; | |
$workerOne->salary = 1000; | |
$workerTwo = new Worker(); | |
$workerTwo->name = 'Вася'; | |
$workerTwo->age = 26; | |
$workerTwo->salary = 2000; | |
echo $workerOne->salary + $workerTwo->salary.'<br>'; | |
echo $workerOne->age + $workerTwo->age.'<br>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment