3v4l.org

run code in 300+ PHP versions simultaneously
#!/usr/bin/php <?php // Take your submitted output $jsonData = '{"msg":"OK","details":[{ "id":"1","score":"233","user_id":"4", "date":"2014-02-03 00:00:00"}, { "id":"2", "score":"1256","user_id":"5", "date":"2014-02-05 00:00:00"},{"id":"4", "score":"123", "user_id":"7", "date":"2014-03-04 00:00:00"},{ "id":"3", "score":"100", "user_id":"6", "date":"2014-03-08 00:00:00"},{ "id":"5", "score":"8", "user_id":"2", "date":"2014-03-13 00:00:00"}], "1st":"2014-02-03 00:00:00", "last":"2014-03-13 00:00:00"}'; // and convert it to an array $origArray=json_decode($jsonData); // We will want an array to hold data $weeklyDetails = array(); // Lets loop through each of your details foreach ($origArray->details as $detail){ // and get the week number $weekNo=date("W", strtotime($detail->date)); // and if we don't already have an array for that week if (! is_array($weeklyDetails["week $weekNo"]) ){ //create it $weeklyDetails["week $weekNo"] = array(); } // lets push the detail into that week array_push($weeklyDetails["week $weekNo"], $detail); } // Assign the new details $origArray->details = $weeklyDetails; // Convert back to json $jsonData = json_encode($origArray); // print it out. print($jsonData);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 36
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 36
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 28
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/YaD9l
function name:  (null)
number of ops:  45
compiled vars:  !0 = $jsonData, !1 = $origArray, !2 = $weeklyDetails, !3 = $detail, !4 = $weekNo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, '%7B%22msg%22%3A%22OK%22%2C%22details%22%3A%5B%7B+%22id%22%3A%221%22%2C%22score%22%3A%22233%22%2C%22user_id%22%3A%224%22%2C+%22date%22%3A%222014-02-03+00%3A00%3A00%22%7D%2C+%7B+%22id%22%3A%222%22%2C+%22score%22%3A%221256%22%2C%22user_id%22%3A%225%22%2C+%22date%22%3A%222014-02-05+00%3A00%3A00%22%7D%2C%7B%22id%22%3A%224%22%2C+%22score%22%3A%22123%22%2C+%22user_id%22%3A%227%22%2C+%22date%22%3A%222014-03-04+00%3A00%3A00%22%7D%2C%7B+%22id%22%3A%223%22%2C+%22score%22%3A%22100%22%2C+%22user_id%22%3A%226%22%2C+%22date%22%3A%222014-03-08+00%3A00%3A00%22%7D%2C%7B+%22id%22%3A%225%22%2C+%22score%22%3A%228%22%2C+%22user_id%22%3A%222%22%2C+%22date%22%3A%222014-03-13+00%3A00%3A00%22%7D%5D%2C+%221st%22%3A%222014-02-03+00%3A00%3A00%22%2C+%22last%22%3A%222014-03-13+00%3A00%3A00%22%7D'
    7     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
   10     5        ASSIGN                                                   !2, <array>
   13     6        FETCH_OBJ_R                                      ~9      !1, 'details'
          7      > FE_RESET_R                                       $10     ~9, ->36
          8    > > FE_FETCH_R                                               $10, !3, ->36
   15     9    >   INIT_FCALL                                               'date'
         10        SEND_VAL                                                 'W'
         11        INIT_FCALL                                               'strtotime'
         12        FETCH_OBJ_R                                      ~11     !3, 'date'
         13        SEND_VAL                                                 ~11
         14        DO_ICALL                                         $12     
         15        SEND_VAR                                                 $12
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !4, $13
   18    18        NOP                                                      
         19        FAST_CONCAT                                      ~15     'week+', !4
         20        FETCH_DIM_R                                      ~16     !2, ~15
         21        TYPE_CHECK                                  128  ~17     ~16
         22        BOOL_NOT                                         ~18     ~17
         23      > JMPZ                                                     ~18, ->28
   20    24    >   NOP                                                      
         25        FAST_CONCAT                                      ~19     'week+', !4
         26        ASSIGN_DIM                                               !2, ~19
         27        OP_DATA                                                  <array>
   23    28    >   INIT_FCALL                                               'array_push'
         29        NOP                                                      
         30        FAST_CONCAT                                      ~21     'week+', !4
         31        FETCH_DIM_W                                      $22     !2, ~21
         32        SEND_REF                                                 $22
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                                 
   13    35      > JMP                                                      ->8
         36    >   FE_FREE                                                  $10
   27    37        ASSIGN_OBJ                                               !1, 'details'
         38        OP_DATA                                                  !2
   30    39        INIT_FCALL                                               'json_encode'
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                         $25     
         42        ASSIGN                                                   !0, $25
   33    43        ECHO                                                     !0
         44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.99 ms | 1400 KiB | 23 Q