3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Question { public $text; public $points = 5; public $answers; public $correctAnswer; public $hint; } function createQuestions() { $questions = []; $q = new Question; $q->text = "Какая планета располагается четвертой по счету от Солнца?"; $q->points = 10; // 10 баллов за ответ $q->answers = array('a' => 'Венера', 'b' => 'Марс', 'c' => 'Юпитер', 'd' => 'Меркурий'); // Варианты ответа $q->correctAnswer = 'b'; // Правильный ответ $q->hint = "Красная планета"; $questions[] = $q; $q = new Question; $q->text = 'Какой город является столицей Великобритании?'; $q->points = 5; $q->answers = array('a' => 'Париж', 'b' => 'Москва', 'c' => 'Нью-Йорк', 'd' => 'Лондон'); $q->correctAnswer = 'd'; $q->hint = "Биг Бен"; $questions[] = $q; $q = new Question; $q->text = 'Кто придумал теорию относительности?'; $q->points = 30; $q->answers = array('a' => 'Джон Леннон', 'b' => 'Джим Моррисон', 'c' => 'Альберт Эйнштейн', 'd' => 'Исаак Ньютон'); $q->correctAnswer = 'c'; $q->hint = "Высунул язык"; $questions[] = $q; return $questions; } function printQuestions($questions) { $number = 1; foreach ($questions as $question) { echo "{$number}. {$question->text}\n"; echo "Варианты ответов:\n"; foreach ($question->answers as $letter => $answer) { echo " {$letter}. {$answer}\n"; } echo "\n"; $number++; } } function checkAnswers($questions, $answers) { if (count($questions) != count($answers)) { die("Число ответов и вопросов не совпадает\n"); } $pointsTotal = 0; $pointsMax = 0; $correctAnswers = 0; $totalQuestions = count($questions); for ($i = 0; $i < count($questions); $i++) { $question = $questions[$i]; // Текущий вопрос $answer = $answers[$i]; // текущий ответ $pointsMax += $question->points; if ($answer == $question->correctAnswer) { $correctAnswers ++; $pointsTotal += $question->points; } else { $number = $i + 1; echo "Неправильный ответ на вопрос №{$number} ({$question->text} Подсказка: $question->hint) \n"; } } echo "Правильных ответов: {$correctAnswers} из {$totalQuestions}, баллов набрано: $pointsTotal из $pointsMax\n"; } $questions = createQuestions(); printQuestions($questions); $answers = array('b', 'd', 'a'); checkAnswers($questions, $answers);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dWVtb
function name:  (null)
number of ops:  12
compiled vars:  !0 = $questions, !1 = $answers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   INIT_FCALL                                               'createquestions'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   93     3        INIT_FCALL                                               'printquestions'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0          
   94     6        ASSIGN                                                   !1, <array>
   95     7        INIT_FCALL                                               'checkanswers'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0          
         11      > RETURN                                                   1

Function createquestions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dWVtb
function name:  createQuestions
number of ops:  48
compiled vars:  !0 = $questions, !1 = $q
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   16     1        NEW                                              $3      'Question'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $3
   17     4        ASSIGN_OBJ                                               !1, 'text'
          5        OP_DATA                                                  '%D0%9A%D0%B0%D0%BA%D0%B0%D1%8F+%D0%BF%D0%BB%D0%B0%D0%BD%D0%B5%D1%82%D0%B0+%D1%80%D0%B0%D1%81%D0%BF%D0%BE%D0%BB%D0%B0%D0%B3%D0%B0%D0%B5%D1%82%D1%81%D1%8F+%D1%87%D0%B5%D1%82%D0%B2%D0%B5%D1%80%D1%82%D0%BE%D0%B9+%D0%BF%D0%BE+%D1%81%D1%87%D0%B5%D1%82%D1%83+%D0%BE%D1%82+%D0%A1%D0%BE%D0%BB%D0%BD%D1%86%D0%B0%3F'
   18     6        ASSIGN_OBJ                                               !1, 'points'
          7        OP_DATA                                                  10
   19     8        ASSIGN_OBJ                                               !1, 'answers'
          9        OP_DATA                                                  <array>
   20    10        ASSIGN_OBJ                                               !1, 'correctAnswer'
         11        OP_DATA                                                  'b'
   21    12        ASSIGN_OBJ                                               !1, 'hint'
         13        OP_DATA                                                  '%D0%9A%D1%80%D0%B0%D1%81%D0%BD%D0%B0%D1%8F+%D0%BF%D0%BB%D0%B0%D0%BD%D0%B5%D1%82%D0%B0'
   23    14        ASSIGN_DIM                                               !0
         15        OP_DATA                                                  !1
   25    16        NEW                                              $12     'Question'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !1, $12
   26    19        ASSIGN_OBJ                                               !1, 'text'
         20        OP_DATA                                                  '%D0%9A%D0%B0%D0%BA%D0%BE%D0%B9+%D0%B3%D0%BE%D1%80%D0%BE%D0%B4+%D1%8F%D0%B2%D0%BB%D1%8F%D0%B5%D1%82%D1%81%D1%8F+%D1%81%D1%82%D0%BE%D0%BB%D0%B8%D1%86%D0%B5%D0%B9+%D0%92%D0%B5%D0%BB%D0%B8%D0%BA%D0%BE%D0%B1%D1%80%D0%B8%D1%82%D0%B0%D0%BD%D0%B8%D0%B8%3F'
   27    21        ASSIGN_OBJ                                               !1, 'points'
         22        OP_DATA                                                  5
   28    23        ASSIGN_OBJ                                               !1, 'answers'
         24        OP_DATA                                                  <array>
   29    25        ASSIGN_OBJ                                               !1, 'correctAnswer'
         26        OP_DATA                                                  'd'
   30    27        ASSIGN_OBJ                                               !1, 'hint'
         28        OP_DATA                                                  '%D0%91%D0%B8%D0%B3+%D0%91%D0%B5%D0%BD'
   32    29        ASSIGN_DIM                                               !0
         30        OP_DATA                                                  !1
   34    31        NEW                                              $21     'Question'
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !1, $21
   35    34        ASSIGN_OBJ                                               !1, 'text'
         35        OP_DATA                                                  '%D0%9A%D1%82%D0%BE+%D0%BF%D1%80%D0%B8%D0%B4%D1%83%D0%BC%D0%B0%D0%BB+%D1%82%D0%B5%D0%BE%D1%80%D0%B8%D1%8E+%D0%BE%D1%82%D0%BD%D0%BE%D1%81%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%BE%D1%81%D1%82%D0%B8%3F'
   36    36        ASSIGN_OBJ                                               !1, 'points'
         37        OP_DATA                                                  30
   37    38        ASSIGN_OBJ                                               !1, 'answers'
         39        OP_DATA                                                  <array>
   38    40        ASSIGN_OBJ                                               !1, 'correctAnswer'
         41        OP_DATA                                                  'c'
   39    42        ASSIGN_OBJ                                               !1, 'hint'
         43        OP_DATA                                                  '%D0%92%D1%8B%D1%81%D1%83%D0%BD%D1%83%D0%BB+%D1%8F%D0%B7%D1%8B%D0%BA'
   41    44        ASSIGN_DIM                                               !0
         45        OP_DATA                                                  !1
   43    46      > RETURN                                                   !0
   44    47*     > RETURN                                                   null

End of function createquestions

Function printquestions:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/dWVtb
function name:  printQuestions
number of ops:  28
compiled vars:  !0 = $questions, !1 = $number, !2 = $question, !3 = $answer, !4 = $letter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        ASSIGN                                                   !1, 1
   50     2      > FE_RESET_R                                       $6      !0, ->26
          3    > > FE_FETCH_R                                               $6, !2, ->26
   51     4    >   ROPE_INIT                                     4  ~9      !1
          5        ROPE_ADD                                      1  ~9      ~9, '.+'
          6        FETCH_OBJ_R                                      ~7      !2, 'text'
          7        ROPE_ADD                                      2  ~9      ~9, ~7
          8        ROPE_END                                      3  ~8      ~9, '%0A'
          9        ECHO                                                     ~8
   53    10        ECHO                                                     '%D0%92%D0%B0%D1%80%D0%B8%D0%B0%D0%BD%D1%82%D1%8B+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%BE%D0%B2%3A%0A'
   55    11        FETCH_OBJ_R                                      ~11     !2, 'answers'
         12      > FE_RESET_R                                       $12     ~11, ->22
         13    > > FE_FETCH_R                                       ~13     $12, !3, ->22
         14    >   ASSIGN                                                   !4, ~13
   56    15        ROPE_INIT                                     5  ~16     '++'
         16        ROPE_ADD                                      1  ~16     ~16, !4
         17        ROPE_ADD                                      2  ~16     ~16, '.+'
         18        ROPE_ADD                                      3  ~16     ~16, !3
         19        ROPE_END                                      4  ~15     ~16, '%0A'
         20        ECHO                                                     ~15
   55    21      > JMP                                                      ->13
         22    >   FE_FREE                                                  $12
   58    23        ECHO                                                     '%0A'
   59    24        PRE_INC                                                  !1
   50    25      > JMP                                                      ->3
         26    >   FE_FREE                                                  $6
   61    27      > RETURN                                                   null

End of function printquestions

Function checkanswers:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 14
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 14
Branch analysis from position: 43
Branch analysis from position: 14
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 14
Branch analysis from position: 43
Branch analysis from position: 14
filename:       /in/dWVtb
function name:  checkAnswers
number of ops:  54
compiled vars:  !0 = $questions, !1 = $answers, !2 = $pointsTotal, !3 = $pointsMax, !4 = $correctAnswers, !5 = $totalQuestions, !6 = $i, !7 = $question, !8 = $answer, !9 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   65     2        COUNT                                            ~10     !0
          3        COUNT                                            ~11     !1
          4        IS_NOT_EQUAL                                             ~10, ~11
          5      > JMPZ                                                     ~12, ->7
   66     6    > > EXIT                                                     '%D0%A7%D0%B8%D1%81%D0%BB%D0%BE+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%BE%D0%B2+%D0%B8+%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81%D0%BE%D0%B2+%D0%BD%D0%B5+%D1%81%D0%BE%D0%B2%D0%BF%D0%B0%D0%B4%D0%B0%D0%B5%D1%82%0A'
   69     7    >   ASSIGN                                                   !2, 0
   70     8        ASSIGN                                                   !3, 0
   71     9        ASSIGN                                                   !4, 0
   72    10        COUNT                                            ~16     !0
         11        ASSIGN                                                   !5, ~16
   74    12        ASSIGN                                                   !6, 0
         13      > JMP                                                      ->40
   75    14    >   FETCH_DIM_R                                      ~19     !0, !6
         15        ASSIGN                                                   !7, ~19
   76    16        FETCH_DIM_R                                      ~21     !1, !6
         17        ASSIGN                                                   !8, ~21
   78    18        FETCH_OBJ_R                                      ~23     !7, 'points'
         19        ASSIGN_OP                                     1          !3, ~23
   80    20        FETCH_OBJ_R                                      ~25     !7, 'correctAnswer'
         21        IS_EQUAL                                                 !8, ~25
         22      > JMPZ                                                     ~26, ->27
   81    23    >   PRE_INC                                                  !4
   82    24        FETCH_OBJ_R                                      ~28     !7, 'points'
         25        ASSIGN_OP                                     1          !2, ~28
         26      > JMP                                                      ->39
   84    27    >   ADD                                              ~30     !6, 1
         28        ASSIGN                                                   !9, ~30
   85    29        ROPE_INIT                                     7  ~35     '%D0%9D%D0%B5%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9+%D0%BE%D1%82%D0%B2%D0%B5%D1%82+%D0%BD%D0%B0+%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81+%E2%84%96'
         30        ROPE_ADD                                      1  ~35     ~35, !9
         31        ROPE_ADD                                      2  ~35     ~35, '+%28'
         32        FETCH_OBJ_R                                      ~32     !7, 'text'
         33        ROPE_ADD                                      3  ~35     ~35, ~32
         34        ROPE_ADD                                      4  ~35     ~35, '+%D0%9F%D0%BE%D0%B4%D1%81%D0%BA%D0%B0%D0%B7%D0%BA%D0%B0%3A+'
         35        FETCH_OBJ_R                                      ~33     !7, 'hint'
         36        ROPE_ADD                                      5  ~35     ~35, ~33
         37        ROPE_END                                      6  ~34     ~35, '%29+%0A'
         38        ECHO                                                     ~34
   74    39    >   PRE_INC                                                  !6
         40    >   COUNT                                            ~40     !0
         41        IS_SMALLER                                               !6, ~40
         42      > JMPNZ                                                    ~41, ->14
   89    43    >   ROPE_INIT                                     9  ~43     '%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D1%85+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%BE%D0%B2%3A+'
         44        ROPE_ADD                                      1  ~43     ~43, !4
         45        ROPE_ADD                                      2  ~43     ~43, '+%D0%B8%D0%B7+'
         46        ROPE_ADD                                      3  ~43     ~43, !5
         47        ROPE_ADD                                      4  ~43     ~43, '%2C+%D0%B1%D0%B0%D0%BB%D0%BB%D0%BE%D0%B2+%D0%BD%D0%B0%D0%B1%D1%80%D0%B0%D0%BD%D0%BE%3A+'
         48        ROPE_ADD                                      5  ~43     ~43, !2
         49        ROPE_ADD                                      6  ~43     ~43, '+%D0%B8%D0%B7+'
         50        ROPE_ADD                                      7  ~43     ~43, !3
         51        ROPE_END                                      8  ~42     ~43, '%0A'
         52        ECHO                                                     ~42
   90    53      > RETURN                                                   null

End of function checkanswers

Class Question: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.43 ms | 1415 KiB | 16 Q