3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ {"recipient_name":"John D", "phone_number":"123456"}, {"recipient_name":"Doe J", "phone_number":"654321"}, {"recipient_name":"Jon Do", "phone_number":"112233"} ]'; $myLargerArray = json_decode($json, true); $myObjArray = (object) ['message_recipients' => array()]; $size = count($myLargerArray); $myObjArray->message_recipients = []; for ($j = 0; $j < $size; $j++) { $myRecipientsObj = new stdClass; $myRecipientsObj->recipient_name = $myLargerArray[$j]['recipient_name']; $myRecipientsObj->phone_number = $myLargerArray[$j]['phone_number']; // var_dump($myRecipientsObj); // This outputs the correct data added from [$j] $myObjArray->message_recipients[] = $myRecipientsObj; } var_dump($myObjArray->message_recipients); // The output shows array elements are being overwritten at each loop iteration
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
Branch analysis from position: 14
filename:       /in/g9Nmr
function name:  (null)
number of ops:  36
compiled vars:  !0 = $json, !1 = $myLargerArray, !2 = $myObjArray, !3 = $size, !4 = $j, !5 = $myRecipientsObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%22recipient_name%22%3A%22John+D%22%2C+%22phone_number%22%3A%22123456%22%7D%2C%0A++++%7B%22recipient_name%22%3A%22Doe+J%22%2C+%22phone_number%22%3A%22654321%22%7D%2C%0A++++%7B%22recipient_name%22%3A%22Jon+Do%22%2C+%22phone_number%22%3A%22112233%22%7D%0A%5D'
    7     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
    8     6        CAST                                          8  ~9      <array>
          7        ASSIGN                                                   !2, ~9
    9     8        COUNT                                            ~11     !1
          9        ASSIGN                                                   !3, ~11
   10    10        ASSIGN_OBJ                                               !2, 'message_recipients'
         11        OP_DATA                                                  <array>
   11    12        ASSIGN                                                   !4, 0
         13      > JMP                                                      ->29
   12    14    >   NEW                                              $15     'stdClass'
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !5, $15
   13    17        FETCH_DIM_R                                      ~19     !1, !4
         18        FETCH_DIM_R                                      ~20     ~19, 'recipient_name'
         19        ASSIGN_OBJ                                               !5, 'recipient_name'
         20        OP_DATA                                                  ~20
   14    21        FETCH_DIM_R                                      ~22     !1, !4
         22        FETCH_DIM_R                                      ~23     ~22, 'phone_number'
         23        ASSIGN_OBJ                                               !5, 'phone_number'
         24        OP_DATA                                                  ~23
   16    25        FETCH_OBJ_W                                      $24     !2, 'message_recipients'
         26        ASSIGN_DIM                                               $24
         27        OP_DATA                                                  !5
   11    28        PRE_INC                                                  !4
         29    >   IS_SMALLER                                               !4, !3
         30      > JMPNZ                                                    ~27, ->14
   18    31    >   INIT_FCALL                                               'var_dump'
         32        FETCH_OBJ_R                                      ~28     !2, 'message_recipients'
         33        SEND_VAL                                                 ~28
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.17 ms | 1400 KiB | 17 Q