3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlstr = '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <Xiami> <ArtistID>179</ArtistID> <ArtistName>Band 1</ArtistName> <XiamiID>9dl4gN1c745</XiamiID> <Streaming>246</Streaming> <Fans>84</Fans> <TotalComments>1992</TotalComments> <AllSongs> <Songs> <SongID>8ILroS998dc</SongID> <SongName>Song 1</SongName> <SongComments>9223</SongComments> </Songs> <Songs> <SongID>8ILLD61a351</SongID> <SongName>Song 2</SongName> <SongComments>7221</SongComments> </Songs> <Songs> <SongID>mTnf0L5d6b9</SongID> <SongName>Song 3</SongName> <SongComments>21212</SongComments> </Songs> <Songs> <SongID>xOd2YIc7f69</SongID> <SongName>Song 4</SongName> <SongComments>422</SongComments> </Songs> <Songs> <SongID>mTmg866314c</SongID> <SongName>Song 5</SongName> <SongComments>81211</SongComments> </Songs> </AllSongs> </Xiami> </rss>'; function popular_songs($Artist) { $Songs = $Artist->xpath('//Songs'); usort($Songs, function ($a, $b) { return $b->SongComments - $a->SongComments; }); return array_slice($Songs, 0, 3); } $xml = simplexml_load_string($xmlstr); foreach($xml->children() as $Artist) { $ArtistName = $Artist->ArtistName; $Streaming = $Artist->Streaming; $Fans = $Artist->Fans; $SongsArrays = $Artist->AllSongs; $SongsCount = $Artist->AllSongs->Songs->count(); $TotalComments = array_reduce($Artist->xpath('//SongComments'), function ($c, $v) { return $c + $v; }, 0); echo $TotalComments . PHP_EOL; $PopularSongs = popular_songs($Artist); print_r($PopularSongs); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 42
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/nS00m
function name:  (null)
number of ops:  44
compiled vars:  !0 = $xmlstr, !1 = $xml, !2 = $Artist, !3 = $ArtistName, !4 = $Streaming, !5 = $Fans, !6 = $SongsArrays, !7 = $SongsCount, !8 = $TotalComments, !9 = $PopularSongs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Crss+version%3D%222.0%22%3E%0A++%3CXiami%3E%0A++++%3CArtistID%3E179%3C%2FArtistID%3E%0A++++%3CArtistName%3EBand+1%3C%2FArtistName%3E%0A++++%3CXiamiID%3E9dl4gN1c745%3C%2FXiamiID%3E%0A++++%3CStreaming%3E246%3C%2FStreaming%3E%0A++++%3CFans%3E84%3C%2FFans%3E%0A++++%3CTotalComments%3E1992%3C%2FTotalComments%3E%0A++++++%3CAllSongs%3E%0A++++++++%3CSongs%3E%0A++++++++++%3CSongID%3E8ILroS998dc%3C%2FSongID%3E%0A++++++++++%3CSongName%3ESong+1%3C%2FSongName%3E%0A++++++++++%3CSongComments%3E9223%3C%2FSongComments%3E%0A++++++++%3C%2FSongs%3E%0A++++++++%3CSongs%3E%0A++++++++++%3CSongID%3E8ILLD61a351%3C%2FSongID%3E%0A++++++++++%3CSongName%3ESong+2%3C%2FSongName%3E%0A++++++++++%3CSongComments%3E7221%3C%2FSongComments%3E%0A++++++++%3C%2FSongs%3E%0A++++++++%3CSongs%3E%0A++++++++++%3CSongID%3EmTnf0L5d6b9%3C%2FSongID%3E%0A++++++++++%3CSongName%3ESong+3%3C%2FSongName%3E%0A++++++++++%3CSongComments%3E21212%3C%2FSongComments%3E%0A++++++++%3C%2FSongs%3E%0A++++++++%3CSongs%3E%0A++++++++++%3CSongID%3ExOd2YIc7f69%3C%2FSongID%3E%0A++++++++++%3CSongName%3ESong+4%3C%2FSongName%3E%0A++++++++++%3CSongComments%3E422%3C%2FSongComments%3E%0A++++++++%3C%2FSongs%3E%0A++++++++%3CSongs%3E%0A++++++++++%3CSongID%3EmTmg866314c%3C%2FSongID%3E%0A++++++++++%3CSongName%3ESong+5%3C%2FSongName%3E%0A++++++++++%3CSongComments%3E81211%3C%2FSongComments%3E%0A++++++++%3C%2FSongs%3E%0A++++%3C%2FAllSongs%3E%0A++%3C%2FXiami%3E%0A%3C%2Frss%3E'
   48     1        INIT_FCALL                                               'simplexml_load_string'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $11     
          4        ASSIGN                                                   !1, $11
   49     5        INIT_METHOD_CALL                                         !1, 'children'
          6        DO_FCALL                                      0  $13     
          7      > FE_RESET_R                                       $14     $13, ->42
          8    > > FE_FETCH_R                                               $14, !2, ->42
   50     9    >   FETCH_OBJ_R                                      ~15     !2, 'ArtistName'
         10        ASSIGN                                                   !3, ~15
   51    11        FETCH_OBJ_R                                      ~17     !2, 'Streaming'
         12        ASSIGN                                                   !4, ~17
   52    13        FETCH_OBJ_R                                      ~19     !2, 'Fans'
         14        ASSIGN                                                   !5, ~19
   53    15        FETCH_OBJ_R                                      ~21     !2, 'AllSongs'
         16        ASSIGN                                                   !6, ~21
   54    17        FETCH_OBJ_R                                      ~23     !2, 'AllSongs'
         18        FETCH_OBJ_R                                      ~24     ~23, 'Songs'
         19        INIT_METHOD_CALL                                         ~24, 'count'
         20        DO_FCALL                                      0  $25     
         21        ASSIGN                                                   !7, $25
   55    22        INIT_FCALL                                               'array_reduce'
         23        INIT_METHOD_CALL                                         !2, 'xpath'
         24        SEND_VAL_EX                                              '%2F%2FSongComments'
         25        DO_FCALL                                      0  $27     
         26        SEND_VAR                                                 $27
         27        DECLARE_LAMBDA_FUNCTION                          ~28     [0]
         28        SEND_VAL                                                 ~28
         29        SEND_VAL                                                 0
         30        DO_ICALL                                         $29     
         31        ASSIGN                                                   !8, $29
   56    32        CONCAT                                           ~31     !8, '%0A'
         33        ECHO                                                     ~31
   57    34        INIT_FCALL                                               'popular_songs'
         35        SEND_VAR                                                 !2
         36        DO_FCALL                                      0  $32     
         37        ASSIGN                                                   !9, $32
   58    38        INIT_FCALL                                               'print_r'
         39        SEND_VAR                                                 !9
         40        DO_ICALL                                                 
   49    41      > JMP                                                      ->8
         42    >   FE_FREE                                                  $14
   59    43      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS00m
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $c, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ADD                                              ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of Dynamic Function 0

Function popular_songs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS00m
function name:  popular_songs
number of ops:  17
compiled vars:  !0 = $Artist, !1 = $Songs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_METHOD_CALL                                         !0, 'xpath'
          2        SEND_VAL_EX                                              '%2F%2FSongs'
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   44     5        INIT_FCALL                                               'usort'
          6        SEND_REF                                                 !1
          7        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                                 
   45    10        INIT_FCALL                                               'array_slice'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 3
         14        DO_ICALL                                         $6      
         15      > RETURN                                                   $6
   46    16*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS00m
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_OBJ_R                                      ~2      !1, 'SongComments'
          3        FETCH_OBJ_R                                      ~3      !0, 'SongComments'
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

End of function popular_songs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.7 ms | 1026 KiB | 19 Q