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); function my_array_column($array, $column) { return array_map(function ($v) use ($column) { return $v[$column]; }, $array); } $array_result = array_map(function ($v) use ($answers) { $v->answer = ($k = array_search($v->id, my_array_column($answers, 'id_question'))) !== false ? $answers[$k]['answer'] : null; return $v; }, $questions); echo str_replace('\/', '/', json_encode($array_result));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t0CEv
function name:  (null)
number of ops:  28
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 >   QM_ASSIGN                                                !0
   3     1        QM_ASSIGN                                                !1
   4     2        INIT_FCALL                                               'json_decode'
         3        SEND_VAR                                                 !0
         4        DO_ICALL                                         $7      
         5        QM_ASSIGN                                                !2
   5     6        INIT_FCALL                                               'json_decode'
         7        SEND_VAR                                                 !1
         8        SEND_VAL                                                 <true>
         9        DO_ICALL                                         $9      
        10        QM_ASSIGN                                                !3
  11    11        INIT_FCALL                                               'array_map'
        12        RAISE_ABSTRACT_ERROR                             ~11     '%00%7Bclosure%7D%2Fin%2Ft0CEv0x7fdb6e47391d'
        13        BIND_LEXICAL                                             ~11, !3
  14    14        SEND_VAL                                                 ~11
        15        SEND_VAR                                                 !2
        16        DO_ICALL                                         $12     
        17        QM_ASSIGN                                                !4
  15    18        INIT_FCALL                                               'str_replace'
        19        SEND_VAL                                                 '%5C%2F'
        20        SEND_VAL                                                 '%2F'
        21        INIT_FCALL                                               'json_encode'
        22        SEND_VAR                                                 !4
        23        DO_ICALL                                         $14     
        24        SEND_VAR                                                 $14
        25        DO_ICALL                                         $15     
        26        ASSIGN_OBJ                                               $15
        27      > RETURN                                                   1

Function my_array_column:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t0CEv
function name:  my_array_column
number of ops:  10
compiled vars:  !0 = $array, !1 = $column
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   RECV                                             !0      
         1        RECV                                             !1      
   8     2        INIT_FCALL                                               'array_map'
         3        RAISE_ABSTRACT_ERROR                             ~2      '%00%7Bclosure%7D%2Fin%2Ft0CEv0x7fdb6e473844'
         4        BIND_LEXICAL                                             ~2, !1
         5        SEND_VAL                                                 ~2
         6        SEND_VAR                                                 !0
         7        DO_ICALL                                         $3      
         8      > RETURN                                                   $3
   9     9*     > RETURN                                                   null

End of function my_array_column

Function %00%7Bclosure%7D%2Fin%2Ft0CEv0x7fdb6e473844:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t0CEv
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $v, !1 = $column
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   8     0  E >   RECV                                             !0      
         1        BIND_STATIC                                              !1
         2        FETCH_DIM_R                                      ~2      !0, !1
         3      > RETURN                                                   ~2
         4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ft0CEv0x7fdb6e473844

Function %00%7Bclosure%7D%2Fin%2Ft0CEv0x7fdb6e47391d:
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/t0CEv
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $v, !1 = $answers, !2 = $k
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  11     0  E >   RECV                                             !0      
         1        BIND_STATIC                                              !1
  12     2        INIT_FCALL                                               'array_search'
         3        FETCH_OBJ_R                                      ~4      !0, 'id'
         4        SEND_VAL                                                 ~4
         5        INIT_FCALL                                               'my_array_column'
         6        SEND_VAR                                                 !1
         7        SEND_VAL                                                 'id_question'
         8        DO_FCALL                                      0  $5      
         9        SEND_VAR                                                 $5
        10        DO_ICALL                                         $6      
        11        QM_ASSIGN                                        $7      !2
        12        IS_EQUAL                                         ~8      $7, <false>
        13      > JMPZ                                                     ~8, ->18
        14    >   FETCH_DIM_R                                      ~9      !1, !2
        15        FETCH_DIM_R                                      ~10     ~9, 'answer'
        16        ASSIGN_BW_OR                                  0  ~11     ~10
        17      > JMP                                                      ->19
        18    >   ASSIGN_BW_OR                                  0  ~11     null
        19    >   ASSIGN_SUB                                    0          !0, 'answer'
        20        OP_DATA                                                  ~11
  13    21      > RETURN                                                   !0
  14    22*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ft0CEv0x7fdb6e47391d

Generated using Vulcan Logic Dumper, using php 7.4.0