Przykładowe rozwiązanie zadania w języku PHP:
3.
class Student {
public $name;
public $average;
public function __construct($name, $average) {
$this->name = $name;
$this->average = $average;
}
$students = [
new Student('Jan Kowalski', $_POST['average1']),
new Student('Anna Nowak', $_POST['average2']),
new Student('Piotr Nowicki', $_POST['average3']),
];
$maxAverage = 0;
$studentWithMaxAverage = null;
foreach ($students as $student) {
if ($student->average > $maxAverage) {
$maxAverage = $student->average;
$studentWithMaxAverage = $student;
echo 'Uczeń z najwyższą średnią to: ' . $studentWithMaxAverage->name;
php
4.
class Employee {
public $salary;
public function __construct($name, $salary) {
$this->salary = $salary;
$employees = [
new Employee('Jan Kowalski', $_POST['salary1']),
new Employee('Anna Nowak', $_POST['salary2']),
new Employee('Piotr Nowicki', $_POST['salary3']),
$maxSalary = 0;
$employeeWithMaxSalary = null;
foreach ($employees as $employee) {
if ($employee->salary > $maxSalary) {
$maxSalary = $employee->salary;
$employeeWithMaxSalary = $employee;
echo 'Pracownik z najwyższą pensją to: ' . $employeeWithMaxSalary->name;
5.
Copy code
$fruits = ['mango', 'aronia', 'papaja', 'banan'];
foreach ($fruits as $fruit) {
echo $fruit . '<br>';
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Przykładowe rozwiązanie zadania w języku PHP:
3.
class Student {
public $name;
public $average;
public function __construct($name, $average) {
$this->name = $name;
$this->average = $average;
}
}
$students = [
new Student('Jan Kowalski', $_POST['average1']),
new Student('Anna Nowak', $_POST['average2']),
new Student('Piotr Nowicki', $_POST['average3']),
];
$maxAverage = 0;
$studentWithMaxAverage = null;
foreach ($students as $student) {
if ($student->average > $maxAverage) {
$maxAverage = $student->average;
$studentWithMaxAverage = $student;
}
}
echo 'Uczeń z najwyższą średnią to: ' . $studentWithMaxAverage->name;
php
4.
class Employee {
public $name;
public $salary;
public function __construct($name, $salary) {
$this->name = $name;
$this->salary = $salary;
}
}
$employees = [
new Employee('Jan Kowalski', $_POST['salary1']),
new Employee('Anna Nowak', $_POST['salary2']),
new Employee('Piotr Nowicki', $_POST['salary3']),
];
$maxSalary = 0;
$employeeWithMaxSalary = null;
foreach ($employees as $employee) {
if ($employee->salary > $maxSalary) {
$maxSalary = $employee->salary;
$employeeWithMaxSalary = $employee;
}
}
echo 'Pracownik z najwyższą pensją to: ' . $employeeWithMaxSalary->name;
5.
Copy code
$fruits = ['mango', 'aronia', 'papaja', 'banan'];
foreach ($fruits as $fruit) {
echo $fruit . '<br>';
}