3v4l.org

run code in 500+ PHP versions simultaneously
<?php // DBからSQLでソートするためにセットされてるダミー日付 define( 'DATE_DAMMY', '1970-01-01 00:00:00' ); // DBからとってきた生レコード $content_row = [ // コメントの情報 'content_id' => 1 ,'content_content' => 'かわいいですね' ,'content_kind' => 'comment' ,'date_create' => '2020-02-01 00:00:01' // コメントが投稿された日 ,'date_his_create' => '1970-01-01 00:00:00' // 自分が投稿したらここも入る ,'date_vote_up' => '2020-02-01 00:00:02' // 自分がコメントを高評価した日 ,'date_clip' => '1970-01-01 00:00:00' // 自分がコメントを保存した日 // 掲示板の情報 ,'parent_content_id' => 10 ,'parent_title' => '猫の掲示板' ,'parent_content_kind' => 'thread' ,'parent_date_favorite' => '1970-01-01 00:00:00' // 自分が掲示板へいいねした日 // コメントの投稿者の情報 ,'author_content_id' => 100 ,'author_content_content' => '花子' ,'author_date_follow' => '2020-01-01 00:00:00' // 自分が投稿者をフォローした日 ]; // 生レコードである $content_row を $content_info へ調整 $content_info = assort($content_row); var_dump($content_info); function assort( $content_row ){ $content_info = []; foreach( $content_row as $k => $v ){ // 掲示板の情報をまとめる if( str_exist($k,'parent') ){ $key = str_replace('parent_','',$k); $content_info['parent_info'][$key] = $v; } // 投稿者の情報をまとめる elseif( str_exist($k,'author') ){ $key = str_replace('author_','',$k); $content_info['author_info'][$key] = $v; $content_info['author_info']['service_name'] = 'mysite'; $content_info['author_info']['kind'] = 'user'; } // コメントの情報 else{ // 日付 if( str_exist($k,'date') ){ // ダミー日付は入れない if( $v == DATE_DAMMY ) continue; // そのまま入れる $content_info[$k] = $v; // jsでソートするときキーが不定だと処理が遅いのでここで date_latest としてソートキーを統一しておく if( !isset($content_info['date_latest']) ){ // まずこの if でなんでもいいので最新日としてセットして、次の else で新しいものに更新していく $content_info['date_latest'] = $v; }else{ // 新しいものに更新していく $date_latest = ( $v > $content_info['date_latest'] ) ? $v : $content_info['date_latest']; $content_info['date_latest'] = $date_latest; } // 判定系はDBでは 0|1 になってるので真偽値にしておく }elseif( str_exist($k,'is_') ){ $content_info[$k] = $v == 1 ? true : false; // 他 }else{ // そのまま入れる $content_info[$k] = $v; } } } return $content_info; } // strpos の代わり function str_exist( $target, $str ){ $is = false; // 配列渡したらエラー if( is_array($target) || is_array($str) ){ error_log('str_exist() : $target - $str : ' . json_encode($target) . ' - ' . json_encode($str) ); } // 普通の strpos を実行 if(strpos($target,$str) !== false){ $is = true; } return $is; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IOIjA
function name:  (null)
number of ops:  13
compiled vars:  !0 = $content_row, !1 = $content_info
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'DATE_DAMMY'
          2        SEND_VAL                                                     '1970-01-01+00%3A00%3A00'
          3        DO_ICALL                                                     
    6     4        ASSIGN                                                       !0, <array>
   27     5        INIT_FCALL_BY_NAME                                           'assort'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0  $4      
          8        ASSIGN                                                       !1, $4
   28     9        INIT_FCALL                                                   'var_dump'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                                     
  101    12      > RETURN                                                       1

Function assort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 79
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 79
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 63
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 52
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 76
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 79
filename:       /in/IOIjA
function name:  assort
number of ops:  82
compiled vars:  !0 = $content_row, !1 = $content_info, !2 = $v, !3 = $k, !4 = $key, !5 = $date_latest
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
   30     1        ASSIGN                                                       !1, <array>
   31     2      > FE_RESET_R                                           $7      !0, ->79
          3    > > FE_FETCH_R                                           ~8      $7, !2, ->79
          4    >   ASSIGN                                                       !3, ~8
   34     5        INIT_FCALL_BY_NAME                                           'str_exist'
          6        SEND_VAR_EX                                                  !3
          7        SEND_VAL_EX                                                  'parent'
          8        DO_FCALL                                          0  $10     
          9      > JMPZ                                                         $10, ->17
   35    10    >   FRAMELESS_ICALL_3                str_replace         ~11     'parent_', ''
         11        OP_DATA                                                      !3
         12        ASSIGN                                                       !4, ~11
   36    13        FETCH_DIM_W                                          $13     !1, 'parent_info'
         14        ASSIGN_DIM                                                   $13, !4
         15        OP_DATA                                                      !2
   34    16      > JMP                                                          ->78
   40    17    >   INIT_FCALL_BY_NAME                                           'str_exist'
         18        SEND_VAR_EX                                                  !3
         19        SEND_VAL_EX                                                  'author'
         20        DO_FCALL                                          0  $15     
         21      > JMPZ                                                         $15, ->35
   41    22    >   FRAMELESS_ICALL_3                str_replace         ~16     'author_', ''
         23        OP_DATA                                                      !3
         24        ASSIGN                                                       !4, ~16
   42    25        FETCH_DIM_W                                          $18     !1, 'author_info'
         26        ASSIGN_DIM                                                   $18, !4
         27        OP_DATA                                                      !2
   43    28        FETCH_DIM_W                                          $20     !1, 'author_info'
         29        ASSIGN_DIM                                                   $20, 'service_name'
         30        OP_DATA                                                      'mysite'
   44    31        FETCH_DIM_W                                          $22     !1, 'author_info'
         32        ASSIGN_DIM                                                   $22, 'kind'
         33        OP_DATA                                                      'user'
   40    34      > JMP                                                          ->78
   51    35    >   INIT_FCALL_BY_NAME                                           'str_exist'
         36        SEND_VAR_EX                                                  !3
         37        SEND_VAL_EX                                                  'date'
         38        DO_FCALL                                          0  $24     
         39      > JMPZ                                                         $24, ->63
   54    40    >   FETCH_CONSTANT                                       ~25     'DATE_DAMMY'
         41        IS_EQUAL                                                     !2, ~25
         42      > JMPZ                                                         ~26, ->44
         43    > > JMP                                                          ->3
   57    44    >   ASSIGN_DIM                                                   !1, !3
         45        OP_DATA                                                      !2
   60    46        ISSET_ISEMPTY_DIM_OBJ                             0  ~28     !1, 'date_latest'
         47        BOOL_NOT                                             ~29     ~28
         48      > JMPZ                                                         ~29, ->52
   63    49    >   ASSIGN_DIM                                                   !1, 'date_latest'
         50        OP_DATA                                                      !2
   60    51      > JMP                                                          ->62
   68    52    >   FETCH_DIM_R                                          ~31     !1, 'date_latest'
         53        IS_SMALLER                                                   ~31, !2
         54      > JMPZ                                                         ~32, ->57
         55    >   QM_ASSIGN                                            ~33     !2
         56      > JMP                                                          ->59
         57    >   FETCH_DIM_R                                          ~34     !1, 'date_latest'
         58        QM_ASSIGN                                            ~33     ~34
         59    >   ASSIGN                                                       !5, ~33
   69    60        ASSIGN_DIM                                                   !1, 'date_latest'
         61        OP_DATA                                                      !5
   51    62    > > JMP                                                          ->78
   73    63    >   INIT_FCALL_BY_NAME                                           'str_exist'
         64        SEND_VAR_EX                                                  !3
         65        SEND_VAL_EX                                                  'is_'
         66        DO_FCALL                                          0  $37     
         67      > JMPZ                                                         $37, ->76
   74    68    >   IS_EQUAL                                                     !2, 1
         69      > JMPZ                                                         ~39, ->72
         70    >   QM_ASSIGN                                            ~40     <true>
         71      > JMP                                                          ->73
         72    >   QM_ASSIGN                                            ~40     <false>
         73    >   ASSIGN_DIM                                                   !1, !3
         74        OP_DATA                                                      ~40
   73    75      > JMP                                                          ->78
   79    76    >   ASSIGN_DIM                                                   !1, !3
         77        OP_DATA                                                      !2
   31    78    > > JMP                                                          ->3
         79    >   FE_FREE                                                      $7
   83    80      > RETURN                                                       !1
   84    81*     > RETURN                                                       null

End of function assort

Function str_exist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 20
Branch analysis from position: 7
filename:       /in/IOIjA
function name:  str_exist
number of ops:  26
compiled vars:  !0 = $target, !1 = $str, !2 = $is
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   87     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   88     2        ASSIGN                                                       !2, <false>
   91     3        TYPE_CHECK                                      128  ~4      !0
          4      > JMPNZ_EX                                             ~4      ~4, ->7
          5    >   TYPE_CHECK                                      128  ~5      !1
          6        BOOL                                                 ~4      ~5
          7    > > JMPZ                                                         ~4, ->20
   92     8    >   INIT_FCALL                                                   'error_log'
          9        INIT_FCALL                                                   'json_encode'
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                             $6      
         12        CONCAT                                               ~7      'str_exist%28%29+%3A+%24target+-+%24str+%3A+', $6
         13        CONCAT                                               ~8      ~7, '+-+'
         14        INIT_FCALL                                                   'json_encode'
         15        SEND_VAR                                                     !1
         16        DO_ICALL                                             $9      
         17        CONCAT                                               ~10     ~8, $9
         18        SEND_VAL                                                     ~10
         19        DO_ICALL                                                     
   96    20    >   FRAMELESS_ICALL_2                strpos              ~12     !0, !1
         21        TYPE_CHECK                                      1018          ~12
         22      > JMPZ                                                         ~13, ->24
   97    23    >   ASSIGN                                                       !2, <true>
  100    24    > > RETURN                                                       !2
  101    25*     > RETURN                                                       null

End of function str_exist

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.44 ms | 2366 KiB | 17 Q