3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_data = <<<JSON {"messages": [ { "id": 1, "customer": "Dr. Kane Hill", "customer_id": 1, "created_at": "2024-11-19 11:18:57", "text": "Hello, how are you?" }, { "id": 2, "customer": "Dr. Kane Hill", "customer_id": 1, "created_at": "2024-11-19 11:20:57", "text": "I am good, thanks! How about you?" }, { "id": 3, "customer": "Prof. Samir McClure III", "customer_id": 2, "created_at": "2024-11-19 11:21:57", "text": "Hey, what time is it?" }, { "id": 4, "customer": "Prof. Samir McClure III", "customer_id": 2, "created_at": "2024-11-19 11:22:57", "text": "It is 3 PM." }, { "id": 5, "customer": "Shad Leffler", "customer_id": 3, "created_at": "2024-11-19 11:23:57", "text": "Did you finish the project?" }, { "id": 6, "customer": "Shad Leffler", "customer_id": 3, "created_at": "2024-11-19 11:24:57", "text": "New mesh" }, { "id": 7, "customer": "Prof. Samir McClure III", "customer_id": 2, "created_at": "2024-11-19 11:26:57", "text": "Not bed?" }, { "id": 8, "customer": "Prof. Samir McClure III", "customer_id": 2, "created_at": "2024-11-19 11:27:57", "text": "Cool?" } ]} JSON; $messages = json_decode($json_data, true)['messages']; $messages2 = []; foreach($messages as $row) { $key = $row['customer_id']; $messages2[$key]['customer'] = $messages2[$key]['customer'] ?? $row['customer']; $messages2[$key]['message_id'] = $messages2[$key]['message_id'] ?? $row['id']; $messages2[$key]['customer_id'] = $messages2[$key]['customer_id'] ?? $row['customer_id']; $messages2[$key]['messages'][] = [ 'id' => $row['id'], 'created_at' => $row['created_at'], 'text' => $row['text'], ]; } $messages2 = array_values($messages2); echo json_encode($messages2, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 47
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 47
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/Z2n4V
function name:  (null)
number of ops:  58
compiled vars:  !0 = $json_data, !1 = $messages, !2 = $messages2, !3 = $row, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%22messages%22%3A+%5B%0A%09%7B%0A%09%09%22id%22%3A+1%2C%0A%09%09%22customer%22%3A+%22Dr.+Kane+Hill%22%2C%0A%09%09%22customer_id%22%3A+1%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A18%3A57%22%2C%0A%09%09%22text%22%3A+%22Hello%2C+how+are+you%3F%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+2%2C%0A%09%09%22customer%22%3A+%22Dr.+Kane+Hill%22%2C%0A%09%09%22customer_id%22%3A+1%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A20%3A57%22%2C%0A%09%09%22text%22%3A+%22I+am+good%2C+thanks%21+How+about+you%3F%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+3%2C%0A%09%09%22customer%22%3A+%22Prof.+Samir+McClure+III%22%2C%0A%09%09%22customer_id%22%3A+2%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A21%3A57%22%2C%0A%09%09%22text%22%3A+%22Hey%2C+what+time+is+it%3F%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+4%2C%0A%09%09%22customer%22%3A+%22Prof.+Samir+McClure+III%22%2C%0A%09%09%22customer_id%22%3A+2%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A22%3A57%22%2C%0A%09%09%22text%22%3A+%22It+is+3+PM.%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+5%2C%0A%09%09%22customer%22%3A+%22Shad+Leffler%22%2C%0A%09%09%22customer_id%22%3A+3%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A23%3A57%22%2C%0A%09%09%22text%22%3A+%22Did+you+finish+the+project%3F%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+6%2C%0A%09%09%22customer%22%3A+%22Shad+Leffler%22%2C%0A%09%09%22customer_id%22%3A+3%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A24%3A57%22%2C%0A%09%09%22text%22%3A+%22New+mesh%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+7%2C%0A%09%09%22customer%22%3A+%22Prof.+Samir+McClure+III%22%2C%0A%09%09%22customer_id%22%3A+2%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A26%3A57%22%2C%0A%09%09%22text%22%3A+%22Not+bed%3F%22%0A%09%7D%2C%0A%09%7B%0A%09%09%22id%22%3A+8%2C%0A%09%09%22customer%22%3A+%22Prof.+Samir+McClure+III%22%2C%0A%09%09%22customer_id%22%3A+2%2C%0A%09%09%22created_at%22%3A+%222024-11-19+11%3A27%3A57%22%2C%0A%09%09%22text%22%3A+%22Cool%3F%22%0A%09%7D%0A%5D%7D'
   64     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $6      
          5        FETCH_DIM_R                                      ~7      $6, 'messages'
          6        ASSIGN                                                   !1, ~7
   66     7        ASSIGN                                                   !2, <array>
   67     8      > FE_RESET_R                                       $10     !1, ->47
          9    > > FE_FETCH_R                                               $10, !3, ->47
   69    10    >   FETCH_DIM_R                                      ~11     !3, 'customer_id'
         11        ASSIGN                                                   !4, ~11
   72    12        FETCH_DIM_IS                                     ~15     !2, !4
         13        FETCH_DIM_IS                                     ~16     ~15, 'customer'
         14        COALESCE                                         ~17     ~16
         15        FETCH_DIM_R                                      ~18     !3, 'customer'
         16        QM_ASSIGN                                        ~17     ~18
   71    17        FETCH_DIM_W                                      $13     !2, !4
         18        ASSIGN_DIM                                               $13, 'customer'
   72    19        OP_DATA                                                  ~17
   75    20        FETCH_DIM_IS                                     ~21     !2, !4
         21        FETCH_DIM_IS                                     ~22     ~21, 'message_id'
         22        COALESCE                                         ~23     ~22
         23        FETCH_DIM_R                                      ~24     !3, 'id'
         24        QM_ASSIGN                                        ~23     ~24
   74    25        FETCH_DIM_W                                      $19     !2, !4
         26        ASSIGN_DIM                                               $19, 'message_id'
   75    27        OP_DATA                                                  ~23
   79    28        FETCH_DIM_IS                                     ~27     !2, !4
         29        FETCH_DIM_IS                                     ~28     ~27, 'customer_id'
         30        COALESCE                                         ~29     ~28
         31        FETCH_DIM_R                                      ~30     !3, 'customer_id'
         32        QM_ASSIGN                                        ~29     ~30
   78    33        FETCH_DIM_W                                      $25     !2, !4
         34        ASSIGN_DIM                                               $25, 'customer_id'
   79    35        OP_DATA                                                  ~29
   83    36        FETCH_DIM_R                                      ~34     !3, 'id'
         37        INIT_ARRAY                                       ~35     ~34, 'id'
   84    38        FETCH_DIM_R                                      ~36     !3, 'created_at'
         39        ADD_ARRAY_ELEMENT                                ~35     ~36, 'created_at'
   85    40        FETCH_DIM_R                                      ~37     !3, 'text'
         41        ADD_ARRAY_ELEMENT                                ~35     ~37, 'text'
   82    42        FETCH_DIM_W                                      $31     !2, !4
         43        FETCH_DIM_W                                      $32     $31, 'messages'
         44        ASSIGN_DIM                                               $32
   85    45        OP_DATA                                                  ~35
   67    46      > JMP                                                      ->9
         47    >   FE_FREE                                                  $10
   89    48        INIT_FCALL                                               'array_values'
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                         $38     
         51        ASSIGN                                                   !2, $38
   91    52        INIT_FCALL                                               'json_encode'
         53        SEND_VAR                                                 !2
         54        SEND_VAL                                                 128
         55        DO_ICALL                                         $40     
         56        ECHO                                                     $40
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.38 ms | 1012 KiB | 16 Q