3v4l.org

run code in 300+ PHP versions simultaneously
<?php $songs = [ ['title' => 'A Change Is Gonna Come'], ['title' => 'A Day In The Life'], ['title' => 'Be My Baby'], ['title' => 'Best Of My Love'], ['title' => 'Billie Jean'], ['title' => 'Bohemian Rhapsody'], ['title' => 'Born To Run'], ['title' => 'Bridge Over Troubled Water'], ['title' => 'Creep'], ['title' => 'Dancing In The Street'], ['title' => 'Dancing Queen'], ['title' => 'Every Breath You Take'], ['title' => 'Family Affair'], ['title' => 'Gimme Shelter'], ['title' => 'God Only Knows'], ['title' => 'God Save The Queen'], ['title' => 'Good Vibrations'], ['title' => 'Hallelujah'], ['title' => 'Heartbreak Hotel'], ['title' => 'Hey Jude'], ['title' => 'Hotel California'], ['title' => 'I Cant Get No Satisfaction'], ['title' => 'I Will Always Love You'], ['title' => 'Imagine'], ['title' => 'Jonny B Good'], ['title' => 'Life On Mars?'], ['title' => 'Like A Rolling Stone'], ['title' => 'Live Forever'], ['title' => 'London Calling'], ['title' => 'My Generation'], ['title' => 'No Woman No Cry'], ['title' => 'One'], ['title' => 'Over The Rainbow'], ['title' => 'Papas Got A Brand New Bag'], ['title' => 'Purple Haze'], ['title' => 'Respect'], ['title' => 'River Deep Mountain High'], ['title' => 'Smells Like Teen Spirit'], ['title' => 'Stairway To Heaven'], ['title' => 'Stand By Me'], ['title' => 'Sultans Of Swing'], ['title' => 'Sweet Child O Mine'], ['title' => 'The Twist'], ['title' => 'Waterloo Sunset'], ['title' => 'Whatd I Say'], ['title' => 'Whats Goin On'], ['title' => 'When Doves Cry'], ['title' => 'Yesterday'], ['title' => 'Your Song'], ['title' => 'Youve Lost That Lovin Feeling'], ]; // Group the songs by initial letter: $grouped = []; foreach($songs as $song) { $initial = $song['title'][0]; $grouped[$initial][] = $song; } // Divide into two sections (as number of alphabets / 2): list($left, $right) = array_chunk($grouped, ceil(count($grouped) / 2), true); // Function to output column: function print_songs(array $songs) { $html = ''; foreach($songs as $letter => $songsByLetter) { $html .= "\n" . $letter . "\n"; foreach($songsByLetter as $song) { $html .= $song['title'] . "\n"; } } return $html; } $left_column = print_songs($left); $right_column = print_songs($right); echo <<<SONGS -------- {$left_column} -------- {$right_column} -------- SONGS;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/iSPCJ
function name:  (null)
number of ops:  42
compiled vars:  !0 = $songs, !1 = $grouped, !2 = $song, !3 = $initial, !4 = $left, !5 = $right, !6 = $left_column, !7 = $right_column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   59     1        ASSIGN                                                   !1, <array>
   61     2      > FE_RESET_R                                       $10     !0, ->11
          3    > > FE_FETCH_R                                               $10, !2, ->11
   62     4    >   FETCH_DIM_R                                      ~11     !2, 'title'
          5        FETCH_DIM_R                                      ~12     ~11, 0
          6        ASSIGN                                                   !3, ~12
   63     7        FETCH_DIM_W                                      $14     !1, !3
          8        ASSIGN_DIM                                               $14
          9        OP_DATA                                                  !2
   61    10      > JMP                                                      ->3
         11    >   FE_FREE                                                  $10
   68    12        INIT_FCALL                                               'array_chunk'
         13        SEND_VAR                                                 !1
         14        INIT_FCALL                                               'ceil'
         15        COUNT                                            ~16     !1
         16        DIV                                              ~17     ~16, 2
         17        SEND_VAL                                                 ~17
         18        DO_ICALL                                         $18     
         19        SEND_VAR                                                 $18
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $19     
         22        FETCH_LIST_R                                     $20     $19, 0
         23        ASSIGN                                                   !4, $20
         24        FETCH_LIST_R                                     $22     $19, 1
         25        ASSIGN                                                   !5, $22
         26        FREE                                                     $19
   84    27        INIT_FCALL                                               'print_songs'
         28        SEND_VAR                                                 !4
         29        DO_FCALL                                      0  $24     
         30        ASSIGN                                                   !6, $24
   85    31        INIT_FCALL                                               'print_songs'
         32        SEND_VAR                                                 !5
         33        DO_FCALL                                      0  $26     
         34        ASSIGN                                                   !7, $26
   88    35        ROPE_INIT                                     5  ~29     '--------%0A'
   89    36        ROPE_ADD                                      1  ~29     ~29, !6
         37        ROPE_ADD                                      2  ~29     ~29, '%0A--------%0A'
   91    38        ROPE_ADD                                      3  ~29     ~29, !7
         39        ROPE_END                                      4  ~28     ~29, '%0A--------'
         40        ECHO                                                     ~28
   94    41      > RETURN                                                   1

Function print_songs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/iSPCJ
function name:  print_songs
number of ops:  19
compiled vars:  !0 = $songs, !1 = $html, !2 = $songsByLetter, !3 = $letter, !4 = $song
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
   74     1        ASSIGN                                                   !1, ''
   75     2      > FE_RESET_R                                       $6      !0, ->16
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->16
          4    >   ASSIGN                                                   !3, ~7
   76     5        CONCAT                                           ~9      '%0A', !3
          6        CONCAT                                           ~10     ~9, '%0A'
          7        ASSIGN_OP                                     8          !1, ~10
   77     8      > FE_RESET_R                                       $12     !2, ->14
          9    > > FE_FETCH_R                                               $12, !4, ->14
   78    10    >   FETCH_DIM_R                                      ~13     !4, 'title'
         11        CONCAT                                           ~14     ~13, '%0A'
         12        ASSIGN_OP                                     8          !1, ~14
   77    13      > JMP                                                      ->9
         14    >   FE_FREE                                                  $12
   75    15      > JMP                                                      ->3
         16    >   FE_FREE                                                  $6
   81    17      > RETURN                                                   !1
   82    18*     > RETURN                                                   null

End of function print_songs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
219.97 ms | 1006 KiB | 17 Q