3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); abstract class Question { public $text; // текст вопроса public $points = 5; // число баллов, по умолчанию 5 public $hint; // подсказка abstract function checkQuestionAndAnswer($answer); } class ChoiceQuestion extends Question { public $options; // варианты ответа public $correctOption; // правильный вариант public function checkQuestionAndAnswer($answer) { if ($this->correctOption == $answer) { return true; } else { return false; } } } class NumericQuestion extends Question { public $correctAnswer; // правильный ответ //public $deviation; // допустимая погрешность public function checkQuestionAndAnswer($answer) { if ($this->correctAnswer == $answer) { return true; } else { return false; } } } // Функция, создающая массив с вопросами: function createQuestions() { // Создаем пустой массив $questions = []; // Вопрос 1 $q1 = new ChoiceQuestion; $q1->text = "Какая планета располагается четвертой по счету от Солнца?"; $q1->points = 10; // 10 баллов за ответ $q1->options = array('a' => 'Венера', 'b' => 'Марс', 'c' => 'Юпитер', 'd' => 'Меркурий'); // Варианты ответа $q1->correctOption = 'b'; // Правильный ответ $q1->hint = 'Сникерс'; // Подсказка $questions[] = $q1; // Вопрос 2 $q2 = new ChoiceQuestion; $q2->text = 'Какой город является столицей Великобритании?'; $q2->points = 5; $q2->options = array('a' => 'Париж', 'b' => 'Москва', 'c' => 'Нью-Йорк', 'd' => 'Лондон'); $q2->correctOption = 'd'; $q2->hint = 'London is the capital of Great Britain'; // Подсказка $questions[] = $q2; // Вопрос 3 $q3 = new ChoiceQuestion; $q3->text = 'Кто придумал теорию относительности?'; $q3->points = 30; $q3->options = array('a' => 'Джон Леннон', 'b' => 'Джим Моррисон', 'c' => 'Альберт Эйнштейн', 'd' => 'Исаак Ньютон'); $q3->correctOption = 'c'; $q3->hint = 'Какой-то еврей... Подождите... Ох, нет...'; // Подсказка $questions[] = $q3; // Вопрос 4 - с выбором цифры $q4 = new NumericQuestion; $q4->text = 'Напишите число Пи до тысячных или хотя бы сотых.'; $q4->points = 30; $q4->correctAnswer = 3.14; $q4->hint = 'Это 3,14здец какой-то...'; // Подсказка $questions[] = $q4; return $questions; } function checkAnswers($questions, $answers) { if (count($questions) != count($answers)) { die("Число ответов и вопросов не совпадает\n"); } $number = 0; $pointsTotal = 0; // сколько набрано баллов $pointsMax = 0; // сколько можно набрать баллов при всех правильных ответах $correctAnswers = 0; // сколько отвечено верно $totalQuestions = count($questions); // Сколько всего вопросов // Если ответ из массива $answers и правильный ответ для соответствующего вопроса совпадают - плюсуются $correctAnswers, $pointsTotal for ($i = 0; $i < count($questions); $i++) { $number = $i + 1; $pointsMax += $questions[$i]->points; if ($questions[$i]->checkQuestionAndAnswer($answers[$i]) == true) { echo "Ответ на вопрос {$number} правильный\n\n"; $correctAnswers++; $pointsTotal += $questions[$i]->points; } else { echo "Ответ на вопрос {$number} НЕправильный\n Подсказка: {$questions[$i]->hint}\n\n"; } } echo "Всего набрано баллов $pointsTotal из $pointsMax.\n Всего правильных ответов: $correctAnswers.\n Всего было вопросов: $totalQuestions\n"; } function printQuestions($questions) { $number = 1; // номер вопроса foreach ($questions as $question) { echo "\n{$number}. {$question->text}\n\n"; if (isset($question->options)) { echo "Варианты ответов:\n"; foreach ($question->options as $letter => $answer) { echo " {$letter}. {$answer}\n"; } } $number++; } } $questions = createQuestions(); $answers = array('b', 'd', 'a', 1); printQuestions($questions); checkAnswers($questions, $answers);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0120.00520.27
8.4.110.0140.00718.67
8.4.100.0130.00717.76
8.4.90.0120.00820.45
8.4.80.0130.00820.65
8.4.70.0090.00819.04
8.4.60.0110.01020.56
8.4.50.0110.01020.57
8.4.40.0150.00020.25
8.4.30.0160.00319.64
8.4.20.0040.01818.80
8.4.10.0000.00919.45
8.3.250.0130.00716.59
8.3.240.0070.00216.75
8.3.230.0130.00516.54
8.3.220.0110.00618.87
8.3.210.0040.00416.76
8.3.200.0040.00416.60
8.3.190.0120.00717.19
8.3.180.0140.00519.01
8.3.170.0180.00017.19
8.3.160.0040.01616.81
8.3.150.0090.00616.72
8.3.140.0000.00818.99
8.3.130.0050.00316.81
8.3.120.0100.00619.28
8.3.110.0030.00620.94
8.3.100.0060.00316.91
8.3.90.0000.00818.43
8.3.80.0000.01218.31
8.3.70.0120.00918.30
8.3.60.0080.00817.00
8.3.50.0130.00621.98
8.3.40.0090.00618.97
8.3.30.0190.00318.65
8.3.20.0070.01121.95
8.3.10.0040.00420.53
8.3.00.0000.00823.66
8.2.290.0140.00517.31
8.2.280.0110.00818.34
8.2.270.0120.00617.46
8.2.260.0070.00717.28
8.2.250.0030.00618.56
8.2.240.0060.00319.19
8.2.230.0000.01022.58
8.2.220.0000.01024.06
8.2.210.0120.00626.77
8.2.200.0090.00316.63
8.2.190.0070.01016.58
8.2.180.0090.00618.66
8.2.170.0090.00622.96
8.2.160.0070.01420.33
8.2.150.0060.00324.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0050.00321.03
8.2.110.0000.00922.25
8.2.100.0060.00617.78
8.2.90.0030.00619.17
8.2.80.0050.00319.34
8.2.70.0080.00017.75
8.2.60.0040.00417.50
8.2.50.0090.00017.49
8.2.40.0040.00420.36
8.2.30.0080.00020.48
8.2.20.0040.00418.21
8.2.10.0050.00218.04
8.2.00.0020.00518.18
8.1.330.0130.00716.14
8.1.320.0120.00821.92
8.1.310.0100.00016.50
8.1.300.0070.01116.29
8.1.290.0070.00318.88
8.1.280.0060.00925.92
8.1.270.0030.00619.11
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00323.97
8.1.230.0090.00319.67
8.1.220.0030.00617.74
8.1.210.0080.00518.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0030.00618.10
8.1.170.0000.00818.50
8.1.160.0050.00318.93
8.1.150.0000.00720.25
8.1.140.0000.00919.68
8.1.130.0040.00418.98
8.1.120.0040.00417.55
8.1.110.0110.00017.38
8.1.100.0000.00817.40
8.1.90.0030.00517.43
8.1.80.0030.00617.55
8.1.70.0030.00317.46
8.1.60.0060.00317.62
8.1.50.0000.00817.60
8.1.40.0040.00417.55
8.1.30.0080.00017.66
8.1.20.0040.00417.59
8.1.10.0030.00617.53
8.1.00.0040.00417.61
8.0.300.0080.00018.77
8.0.290.0000.00916.88
8.0.280.0080.00018.55
8.0.270.0040.00417.30
8.0.260.0040.00417.22
8.0.250.0030.00317.00
8.0.240.0040.00416.92
8.0.230.0000.00717.03
8.0.220.0000.00716.82
8.0.210.0040.00416.90
8.0.200.0030.00317.00
8.0.190.0040.00416.96
8.0.180.0000.00716.87
8.0.170.0020.00517.00
8.0.160.0040.00417.05
8.0.150.0000.00716.91
8.0.140.0080.00016.79
8.0.130.0000.00613.39
8.0.120.0040.00416.93
8.0.110.0000.00817.03
8.0.100.0000.00816.75
8.0.90.0040.00416.96
8.0.80.0060.01116.93
8.0.70.0030.00616.79
8.0.60.0050.00316.77
8.0.50.0040.00416.96
8.0.30.0130.00817.07
8.0.20.0090.01117.40
8.0.10.0000.00917.17
8.0.00.0030.01616.69
7.4.330.0060.00015.55
7.4.320.0030.00316.62
7.4.300.0030.00316.65
7.4.290.0000.00716.49
7.4.280.0030.00316.65
7.4.270.0060.00316.59
7.4.260.0050.00316.57
7.4.250.0030.00416.50
7.4.240.0070.00016.58
7.4.230.0070.00016.75
7.4.220.0120.00616.64
7.4.210.0040.01216.59
7.4.200.0080.00016.36
7.4.160.0080.00816.67
7.4.150.0130.00717.40
7.4.140.0110.01017.86
7.4.130.0130.00716.43
7.4.120.0120.00916.64
7.4.110.0100.00716.61
7.4.100.0160.00316.34
7.4.90.0120.00616.59
7.4.80.0120.00419.39
7.4.70.0090.00916.63
7.4.60.0100.00616.71
7.4.50.0040.00816.33
7.4.40.0030.01316.60
7.4.30.0080.00816.45
7.4.00.0050.01114.82
7.3.330.0000.00513.39
7.3.320.0050.00013.24
7.3.310.0070.00016.41
7.3.300.0030.00316.41
7.3.290.0050.00316.43
7.3.280.0090.00916.38
7.3.270.0160.00617.40
7.3.260.0140.00316.67
7.3.250.0080.01016.54
7.3.240.0120.00916.56
7.3.230.0100.00716.48
7.3.210.0090.00916.46
7.3.200.0150.00616.53
7.3.190.0100.00716.71
7.3.180.0120.00616.38
7.3.170.0070.01416.48
7.3.160.0100.00716.59
7.3.120.0030.01315.04
7.3.110.0070.00714.68
7.3.100.0070.00614.62
7.3.90.0040.00814.91
7.3.80.0030.00914.93
7.3.70.0060.01215.09
7.3.60.0030.01215.05
7.3.50.0110.00714.66
7.3.40.0070.00714.91
7.3.30.0110.00414.60
7.3.20.0060.00916.75
7.3.10.0070.00516.59
7.3.00.0000.01516.66
7.2.330.0100.01716.86
7.2.320.0090.00816.89
7.2.310.0080.00816.97
7.2.300.0100.00716.82
7.2.290.0070.01616.77
7.2.250.0040.01215.19
7.2.240.0130.00715.35
7.2.230.0100.00715.04
7.2.220.0100.00614.92
7.2.210.0060.00914.75
7.2.200.0130.00715.23
7.2.190.0040.01215.00
7.2.180.0040.01215.15
7.2.170.0030.01615.11
7.2.130.0100.00717.03
7.2.120.0040.01116.84
7.2.110.0070.00716.96
7.2.100.0040.00716.98
7.2.90.0060.00616.93
7.2.80.0000.01416.84
7.2.70.0040.01116.88
7.2.60.0030.01216.86
7.2.50.0110.00816.87
7.2.40.0040.00416.90
7.2.30.0060.00616.98
7.2.20.0040.00416.98
7.2.10.0030.00917.02
7.2.00.0030.00616.86
7.1.330.0090.00415.70
7.1.320.0090.00616.02
7.1.310.0040.01415.66
7.1.300.0070.00715.63
7.1.290.0090.01015.82
7.1.280.0030.01415.91
7.1.270.0070.00715.76
7.1.260.0080.00315.43
7.1.250.0070.00315.76
7.1.200.0000.01115.83
7.1.70.0050.00517.21
7.1.60.0000.01117.26
7.1.20.2470.07336.46
7.1.10.1500.06020.41
7.1.00.0930.06720.56
7.0.200.0070.01016.82
7.0.160.2200.07020.23
7.0.150.0930.06320.20
7.0.140.0870.06320.13
7.0.130.0800.05320.11
7.0.120.0870.07020.08
7.0.110.1200.06020.14
7.0.100.1470.07720.29
7.0.90.1000.07320.13
7.0.80.1330.07719.95
7.0.70.1170.08720.17
7.0.60.0900.07319.98
7.0.50.0770.05319.98
7.0.40.1470.06020.13
7.0.30.1400.07020.04
7.0.20.1030.06020.10
7.0.10.0800.04720.07
7.0.00.1600.07019.95

preferences:
27.09 ms | 403 KiB | 5 Q