3v4l.org

run code in 300+ PHP versions simultaneously
<?php $listOfPosts = [ [ 'date' => '2017-06-01', 'id' => 1, ], [ 'date' => '2017-06-01', 'id' => 2, ], [ 'date' => '2017-06-01', 'id' => 3, ], [ 'date' => '2017-06-02', 'id' => 4, ], [ 'date' => '2017-06-03', 'id' => 5, ], [ 'date' => '2017-06-04', 'id' => 6, ], ]; $listOfPostsPage2 = [ [ 'date' => '2017-06-05', 'id' => 1, ], [ 'date' => '2017-06-06', 'id' => 2, ], [ 'date' => '2017-06-07', 'id' => 3, ], [ 'date' => '2017-06-08', 'id' => 4, ] ]; $amountOfDays = 6; $newPostsArr = []; foreach($listOfPosts as $tmp) { if (count($newPostsArr) === $amountOfDays) { var_dump('All days added'); // We are done. break; } $newPostsArr[$tmp['date']][] = $tmp; } // Or like this function iteratePosts($pages, $newPosts) { foreach($pages as $tmp) { $newPosts[$tmp['date']][] = $tmp; } return $newPosts; } $newPostsArr = iteratePosts($listOfPosts, $newPostsArr); if (count($newPostsArr) < $amountOfDays) { // Fetch new page, keep adding entries var_dump('iterating again..'); $newPostsArr = iteratePosts($listOfPostsPage2, $newPostsArr); } var_dump($newPostsArr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 18
Branch analysis from position: 18
filename:       /in/EvjA3
function name:  (null)
number of ops:  39
compiled vars:  !0 = $listOfPosts, !1 = $listOfPostsPage2, !2 = $amountOfDays, !3 = $newPostsArr, !4 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1        ASSIGN                                                   !1, <array>
   49     2        ASSIGN                                                   !2, 6
   50     3        ASSIGN                                                   !3, <array>
   52     4      > FE_RESET_R                                       $9      !0, ->18
          5    > > FE_FETCH_R                                               $9, !4, ->18
   53     6    >   COUNT                                            ~10     !3
          7        IS_IDENTICAL                                             !2, ~10
          8      > JMPZ                                                     ~11, ->13
   54     9    >   INIT_FCALL                                               'var_dump'
         10        SEND_VAL                                                 'All+days+added'
         11        DO_ICALL                                                 
   56    12      > JMP                                                      ->18
   59    13    >   FETCH_DIM_R                                      ~13     !4, 'date'
         14        FETCH_DIM_W                                      $14     !3, ~13
         15        ASSIGN_DIM                                               $14
         16        OP_DATA                                                  !4
   52    17      > JMP                                                      ->5
         18    >   FE_FREE                                                  $9
   71    19        INIT_FCALL                                               'iterateposts'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !3
         22        DO_FCALL                                      0  $16     
         23        ASSIGN                                                   !3, $16
   73    24        COUNT                                            ~18     !3
         25        IS_SMALLER                                               ~18, !2
         26      > JMPZ                                                     ~19, ->35
   75    27    >   INIT_FCALL                                               'var_dump'
         28        SEND_VAL                                                 'iterating+again..'
         29        DO_ICALL                                                 
   76    30        INIT_FCALL                                               'iterateposts'
         31        SEND_VAR                                                 !1
         32        SEND_VAR                                                 !3
         33        DO_FCALL                                      0  $21     
         34        ASSIGN                                                   !3, $21
   79    35    >   INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Function iterateposts:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/EvjA3
function name:  iteratePosts
number of ops:  12
compiled vars:  !0 = $pages, !1 = $newPosts, !2 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   64     2      > FE_RESET_R                                       $3      !0, ->9
          3    > > FE_FETCH_R                                               $3, !2, ->9
   65     4    >   FETCH_DIM_R                                      ~4      !2, 'date'
          5        FETCH_DIM_W                                      $5      !1, ~4
          6        ASSIGN_DIM                                               $5
          7        OP_DATA                                                  !2
   64     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $3
   68    10      > RETURN                                                   !1
   69    11*     > RETURN                                                   null

End of function iterateposts

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.36 ms | 1394 KiB | 17 Q