3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_question = '[ { "id": "8", "question": "Shop sign/billboard " }, { "id": "10", "question": "Pylon" }, { "id": "11", "question": "Banner" }, { "id": "12", "question": "Sport" }, { "id": "14", "question": "Matic " }, { "id": "16", "question": "Cub" } ]'; $array_answer = '[ { "id": "1b9fa84e-0f2f-11e9-b673-005056be36b2", "answer": "3", "id_question": "16" }, { "id": "bc82c3fd-0f2e-11e9-b673-005056be36b2", "answer": "1", "id_question": "11" }, { "id": "cc9363f1-0f2e-11e9-b673-005056be36b2", "answer": "3", "id_question": "12" }, { "id": "f1dfa8b5-0f2e-11e9-b673-005056be36b2", "answer": "1", "id_question": "14" } ]'; $questions = json_decode($array_question); $answers = json_decode($array_answer, true); $array_result = array_map(function ($v) use ($answers) { $v->answer = ($k = array_search($v->id, array_column($answers, 'id_question'))) !== false ? $answers[$k]['answer'] : null; return $v; }, $questions); print_r(json_encode($array_result, JSON_UNESCAPED_SLASHES));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/323RX
function name:  (null)
number of ops:  26
compiled vars:  !0 = $array_question, !1 = $array_answer, !2 = $questions, !3 = $answers, !4 = $array_result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%5B+%7B+%22id%22%3A+%228%22%2C+%22question%22%3A+%22Shop+sign%2Fbillboard+%22+%7D%2C+%7B+%22id%22%3A+%2210%22%2C+%22question%22%3A+%22Pylon%22+%7D%2C+%7B+%22id%22%3A+%2211%22%2C+%22question%22%3A+%22Banner%22+%7D%2C+%7B+%22id%22%3A+%2212%22%2C+%22question%22%3A+%22Sport%22+%7D%2C+%7B+%22id%22%3A+%2214%22%2C+%22question%22%3A+%22Matic+%22+%7D%2C+%7B+%22id%22%3A+%2216%22%2C+%22question%22%3A+%22Cub%22+%7D+%5D'
    3     1        ASSIGN                                                   !1, '%5B+%7B+%22id%22%3A+%221b9fa84e-0f2f-11e9-b673-005056be36b2%22%2C+%22answer%22%3A+%223%22%2C+%22id_question%22%3A+%2216%22+%7D%2C+%7B+%22id%22%3A+%22bc82c3fd-0f2e-11e9-b673-005056be36b2%22%2C+%22answer%22%3A+%221%22%2C+%22id_question%22%3A+%2211%22+%7D%2C+%7B+%22id%22%3A+%22cc9363f1-0f2e-11e9-b673-005056be36b2%22%2C+%22answer%22%3A+%223%22%2C+%22id_question%22%3A+%2212%22+%7D%2C+%7B+%22id%22%3A+%22f1dfa8b5-0f2e-11e9-b673-005056be36b2%22%2C+%22answer%22%3A+%221%22%2C+%22id_question%22%3A+%2214%22+%7D+%5D'
    4     2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !2, $7
    5     6        INIT_FCALL                                               'json_decode'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !3, $9
    7    11        INIT_FCALL                                               'array_map'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F323RX%3A7%240'
         13        BIND_LEXICAL                                             ~11, !3
   10    14        SEND_VAL                                                 ~11
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $12     
    7    17        ASSIGN                                                   !4, $12
   11    18        INIT_FCALL                                               'print_r'
         19        INIT_FCALL                                               'json_encode'
         20        SEND_VAR                                                 !4
         21        SEND_VAL                                                 64
         22        DO_ICALL                                         $14     
         23        SEND_VAR                                                 $14
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F323RX%3A7%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/323RX
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $v, !1 = $answers, !2 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    8     2        INIT_FCALL                                               'array_search'
          3        FETCH_OBJ_R                                      ~4      !0, 'id'
          4        SEND_VAL                                                 ~4
          5        INIT_FCALL                                               'array_column'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'id_question'
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        ASSIGN                                           ~7      !2, $6
         12        TYPE_CHECK                                  1018          ~7
         13      > JMPZ                                                     ~8, ->18
         14    >   FETCH_DIM_R                                      ~9      !1, !2
         15        FETCH_DIM_R                                      ~10     ~9, 'answer'
         16        QM_ASSIGN                                        ~11     ~10
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~11     null
         19    >   ASSIGN_OBJ                                               !0, 'answer'
         20        OP_DATA                                                  ~11
    9    21      > RETURN                                                   !0
   10    22*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F323RX%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.77 ms | 1400 KiB | 25 Q