3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); ini_set('display_errors', 1); $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 = []; $messageCounter = 0; foreach($messages as $row) { $key = $row['customer_id']; if(!isset($messages2[$key])) { $messages2[$key] = [ 'customer' => $row['customer'], 'message_id' => (++$messageCounter), 'customer_id' => $row['customer_id'], 'messages' => [], ]; } $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 = 17, Position 2 = 43
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 43
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 32
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/mZQIN
function name:  (null)
number of ops:  54
compiled vars:  !0 = $json_data, !1 = $messages, !2 = $messages2, !3 = $messageCounter, !4 = $row, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    3     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 1
          6        DO_ICALL                                                 
    5     7        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'
   66     8        INIT_FCALL                                               'json_decode'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $9      
         12        FETCH_DIM_R                                      ~10     $9, 'messages'
         13        ASSIGN                                                   !1, ~10
   68    14        ASSIGN                                                   !2, <array>
   69    15        ASSIGN                                                   !3, 0
   70    16      > FE_RESET_R                                       $14     !1, ->43
         17    > > FE_FETCH_R                                               $14, !4, ->43
   72    18    >   FETCH_DIM_R                                      ~15     !4, 'customer_id'
         19        ASSIGN                                                   !5, ~15
   74    20        ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !2, !5
         21        BOOL_NOT                                         ~18     ~17
         22      > JMPZ                                                     ~18, ->32
   76    23    >   FETCH_DIM_R                                      ~20     !4, 'customer'
         24        INIT_ARRAY                                       ~21     ~20, 'customer'
   77    25        PRE_INC                                          ~22     !3
         26        ADD_ARRAY_ELEMENT                                ~21     ~22, 'message_id'
   78    27        FETCH_DIM_R                                      ~23     !4, 'customer_id'
         28        ADD_ARRAY_ELEMENT                                ~21     ~23, 'customer_id'
   76    29        ADD_ARRAY_ELEMENT                                ~21     <array>, 'messages'
   75    30        ASSIGN_DIM                                               !2, !5
   76    31        OP_DATA                                                  ~21
   85    32    >   FETCH_DIM_R                                      ~27     !4, 'id'
         33        INIT_ARRAY                                       ~28     ~27, 'id'
   86    34        FETCH_DIM_R                                      ~29     !4, 'created_at'
         35        ADD_ARRAY_ELEMENT                                ~28     ~29, 'created_at'
   87    36        FETCH_DIM_R                                      ~30     !4, 'text'
         37        ADD_ARRAY_ELEMENT                                ~28     ~30, 'text'
   84    38        FETCH_DIM_W                                      $24     !2, !5
         39        FETCH_DIM_W                                      $25     $24, 'messages'
         40        ASSIGN_DIM                                               $25
   87    41        OP_DATA                                                  ~28
   70    42      > JMP                                                      ->17
         43    >   FE_FREE                                                  $14
   91    44        INIT_FCALL                                               'array_values'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                         $31     
         47        ASSIGN                                                   !2, $31
   93    48        INIT_FCALL                                               'json_encode'
         49        SEND_VAR                                                 !2
         50        SEND_VAL                                                 128
         51        DO_ICALL                                         $33     
         52        ECHO                                                     $33
         53      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.67 ms | 1079 KiB | 18 Q