3v4l.org

run code in 300+ PHP versions simultaneously
<?php $reporting_data = array( 'category_name' => '33287*100*prescription*1,32457*1250*lab*1,32459*1500*lab*1,32460*400*lab*1,32461*600*lab*1,32468*950*lab*1,32470*950*lab*1,33291*2500*lab*1,33292*2500*lab*1,47516*2000*lab*1,49209*0*lab*1,56835*2400*lab*1,56836*2400*lab*1', 'patient' => '28370', 'date' => 1643030497, 'ref' => '371', ); // Create array of objects $reporting_data_as_objects[] = (object)$reporting_data; $results = []; foreach ($reporting_data_as_objects as &$obj) { // Setup base data that is shared across all items $obj->reception_data_sum = 0; $obj->references_data_sum = 0; $obj->actual_price = 0; $category_names = explode(',', $obj->category_name); // Loop over the comma-delimited parts of category_name foreach ($category_names as $category_name) { // Clone our template object $tmp = clone $obj; // The second item of the asterisk-delimted field is the price // We used $_ to indicate that we aren't interested in the first item. list($_, $sale_value) = explode('*', $category_name); // Set object-specific fields on our clone $tmp->category_name = $category_name; $tmp->actual_price = (int)$sale_value; // Add the clone to the array $results[] = $tmp; } } // Always unset by-ref variables of a foreach unset($obj); print_r($results);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 6, Position 2 = 42
Branch analysis from position: 6
2 jumps found. (Code = 126) Position 1 = 7, Position 2 = 42
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 40
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 40
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 40
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/95KAQ
function name:  (null)
number of ops:  48
compiled vars:  !0 = $reporting_data, !1 = $reporting_data_as_objects, !2 = $results, !3 = $obj, !4 = $category_names, !5 = $category_name, !6 = $tmp, !7 = $_, !8 = $sale_value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        CAST                                          8  ~11     !0
          2        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  ~11
   13     4        ASSIGN                                                   !2, <array>
   14     5      > FE_RESET_RW                                      $13     !1, ->42
          6    > > FE_FETCH_RW                                              $13, !3, ->42
   17     7    >   ASSIGN_OBJ                                               !3, 'reception_data_sum'
          8        OP_DATA                                                  0
   18     9        ASSIGN_OBJ                                               !3, 'references_data_sum'
         10        OP_DATA                                                  0
   19    11        ASSIGN_OBJ                                               !3, 'actual_price'
         12        OP_DATA                                                  0
   21    13        INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '%2C'
         15        FETCH_OBJ_R                                      ~17     !3, 'category_name'
         16        SEND_VAL                                                 ~17
         17        DO_ICALL                                         $18     
         18        ASSIGN                                                   !4, $18
   24    19      > FE_RESET_R                                       $20     !4, ->40
         20    > > FE_FETCH_R                                               $20, !5, ->40
   27    21    >   CLONE                                            ~21     !3
         22        ASSIGN                                                   !6, ~21
   31    23        INIT_FCALL                                               'explode'
         24        SEND_VAL                                                 '%2A'
         25        SEND_VAR                                                 !5
         26        DO_ICALL                                         $23     
         27        FETCH_LIST_R                                     $24     $23, 0
         28        ASSIGN                                                   !7, $24
         29        FETCH_LIST_R                                     $26     $23, 1
         30        ASSIGN                                                   !8, $26
         31        FREE                                                     $23
   34    32        ASSIGN_OBJ                                               !6, 'category_name'
         33        OP_DATA                                                  !5
   35    34        CAST                                          4  ~30     !8
         35        ASSIGN_OBJ                                               !6, 'actual_price'
         36        OP_DATA                                                  ~30
   38    37        ASSIGN_DIM                                               !2
         38        OP_DATA                                                  !6
   24    39      > JMP                                                      ->20
         40    >   FE_FREE                                                  $20
   14    41      > JMP                                                      ->6
         42    >   FE_FREE                                                  $13
   43    43        UNSET_CV                                                 !3
   45    44        INIT_FCALL                                               'print_r'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.19 ms | 1016 KiB | 15 Q