3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = '[{"_id":"123","books":[{"author":"John","title":"The Book"},{"author":"Smith","title":"Something!"}]},{"_id":"321","books":[{"author":"John","title":"The Book"}]}]'; $array = json_decode($json, 1); $ids = []; foreach($array as $v) { foreach($v['books'] as $book){ $books[] = $book; } } print_r($books); echo json_encode($books); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 15
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/hdJ8H
function name:  (null)
number of ops:  26
compiled vars:  !0 = $json, !1 = $array, !2 = $ids, !3 = $v, !4 = $book, !5 = $books
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, '%5B%7B%22_id%22%3A%22123%22%2C%22books%22%3A%5B%7B%22author%22%3A%22John%22%2C%22title%22%3A%22The+Book%22%7D%2C%7B%22author%22%3A%22Smith%22%2C%22title%22%3A%22Something%21%22%7D%5D%7D%2C%7B%22_id%22%3A%22321%22%2C%22books%22%3A%5B%7B%22author%22%3A%22John%22%2C%22title%22%3A%22The+Book%22%7D%5D%7D%5D'
    4     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     1
          4        DO_ICALL                                             $7      
          5        ASSIGN                                                       !1, $7
    5     6        ASSIGN                                                       !2, <array>
    6     7      > FE_RESET_R                                           $10     !1, ->17
          8    > > FE_FETCH_R                                                   $10, !3, ->17
    7     9    >   FETCH_DIM_R                                          ~11     !3, 'books'
         10      > FE_RESET_R                                           $12     ~11, ->15
         11    > > FE_FETCH_R                                                   $12, !4, ->15
    8    12    >   ASSIGN_DIM                                                   !5
         13        OP_DATA                                                      !4
    7    14      > JMP                                                          ->11
         15    >   FE_FREE                                                      $12
    6    16      > JMP                                                          ->8
         17    >   FE_FREE                                                      $10
   12    18        INIT_FCALL                                                   'print_r'
         19        SEND_VAR                                                     !5
         20        DO_ICALL                                                     
   13    21        INIT_FCALL                                                   'json_encode'
         22        SEND_VAR                                                     !5
         23        DO_ICALL                                             $15     
         24        ECHO                                                         $15
   14    25      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
223.31 ms | 2287 KiB | 16 Q