3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( // Sub-array 1 array ( // Story 'Monkey 1' - Has identical sub-sub-arrays 'Monkey 2' and 'Monkey 3' and will be merged with them. array ( "header" => "This is a story about a monkey.", 'keywords' => array( "Trees", "Monkey", "Flying", "Drink", "Vacation", "Coconut", "Big", "Bonobo", "Climbing") ), // Story 'Cat 1' - Has identical sub-sub-array 'Cat 2' and will be merged with it. array ( "header" => "Here's a catarific story about a cat", 'keywords' => array( "meauw", "raaaw", "kitty", "growup", "Fun", "claws", "fish", "salmon") ) ), // Sub-array 2 array ( // Story 'Monkey 2' - Has identical sub-sub-arrays 'Monkey 1' and 'Monkey 3' and will be merged with them. array ( "header" => "This is another, but different story, about a monkey.", 'keywords' => array( "Monkey", "Big", "Trees", "Bonobo", "Fun", "Dance", "Cow", "Coconuts") ), // Story 'Cat 2' - Has identical sub-sub-array 'Cat 1' and will be merged with it. array ( "header" => "Here's a different story about a cat", 'keywords' => array( "meauwe", "ball", "cat", "kitten", "claws", "sleep", "fish", "purr") ) ), // Sub-array 3 array ( // Story 'Monkey 3' - Has identical sub-sub-arrays 'Monkey 1' and 'Monkey 2' and will be merged with them. array ( "header" => "This is a third story about a monkey.", 'keywords' => array( "Jungle", "tree", "monkey", "Bonobo", "Fun", "Dance", "climbing", "Coconut", "pretty") ), // Story 'Fireman 1' - Has no identical sub-sub-arrays and will not be merged. array ( "header" => "This is a story about a fireman", 'keywords' => array( "fire", "explosion", "burning", "rescue", "happy", "help", "water", "car") ) ) ); $new =[]; foreach($array as $subarr){ $new = array_merge($new, $subarr); } var_dump($new); foreach($new as $key => $story){ $words = "/" . implode("|", $story["keywords"]) . "/i"; foreach($new as $key2 => $story2){ if($key != $key2 && $key2 > $key){ if(count(preg_grep($words, $story2["keywords"])) >1){ echo $key . " " . $key2 . "\n"; echo $story["header"] . " = " . $story2["header"] ."\n\n"; $res[$key] = ["header" => [$story["header"], $story2["header"]], "keywords" => array_merge($story["keywords"], $story2["keywords"])]; } } } } //var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 68
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 68
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 66
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 66
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 65
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 65
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 65
Branch analysis from position: 65
Branch analysis from position: 32
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 66
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 10
filename:       /in/45qtD
function name:  (null)
number of ops:  70
compiled vars:  !0 = $array, !1 = $new, !2 = $subarr, !3 = $story, !4 = $key, !5 = $words, !6 = $story2, !7 = $key2, !8 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   45     1        ASSIGN                                                   !1, <array>
   46     2      > FE_RESET_R                                       $11     !0, ->10
          3    > > FE_FETCH_R                                               $11, !2, ->10
   47     4    >   INIT_FCALL                                               'array_merge'
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $12     
          8        ASSIGN                                                   !1, $12
   46     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $11
   49    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   50    14      > FE_RESET_R                                       $15     !1, ->68
         15    > > FE_FETCH_R                                       ~16     $15, !3, ->68
         16    >   ASSIGN                                                   !4, ~16
   51    17        INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '%7C'
         19        FETCH_DIM_R                                      ~18     !3, 'keywords'
         20        SEND_VAL                                                 ~18
         21        DO_ICALL                                         $19     
         22        CONCAT                                           ~20     '%2F', $19
         23        CONCAT                                           ~21     ~20, '%2Fi'
         24        ASSIGN                                                   !5, ~21
   52    25      > FE_RESET_R                                       $23     !1, ->66
         26    > > FE_FETCH_R                                       ~24     $23, !6, ->66
         27    >   ASSIGN                                                   !7, ~24
   53    28        IS_NOT_EQUAL                                     ~26     !4, !7
         29      > JMPZ_EX                                          ~26     ~26, ->32
         30    >   IS_SMALLER                                       ~27     !4, !7
         31        BOOL                                             ~26     ~27
         32    > > JMPZ                                                     ~26, ->65
   54    33    >   INIT_FCALL                                               'preg_grep'
         34        SEND_VAR                                                 !5
         35        FETCH_DIM_R                                      ~28     !6, 'keywords'
         36        SEND_VAL                                                 ~28
         37        DO_ICALL                                         $29     
         38        COUNT                                            ~30     $29
         39        IS_SMALLER                                               1, ~30
         40      > JMPZ                                                     ~31, ->65
   55    41    >   CONCAT                                           ~32     !4, '+'
         42        CONCAT                                           ~33     ~32, !7
         43        CONCAT                                           ~34     ~33, '%0A'
         44        ECHO                                                     ~34
   56    45        FETCH_DIM_R                                      ~35     !3, 'header'
         46        CONCAT                                           ~36     ~35, '+%3D+'
         47        FETCH_DIM_R                                      ~37     !6, 'header'
         48        CONCAT                                           ~38     ~36, ~37
         49        CONCAT                                           ~39     ~38, '%0A%0A'
         50        ECHO                                                     ~39
   57    51        FETCH_DIM_R                                      ~41     !3, 'header'
         52        INIT_ARRAY                                       ~42     ~41
         53        FETCH_DIM_R                                      ~43     !6, 'header'
         54        ADD_ARRAY_ELEMENT                                ~42     ~43
         55        INIT_ARRAY                                       ~44     ~42, 'header'
         56        INIT_FCALL                                               'array_merge'
         57        FETCH_DIM_R                                      ~45     !3, 'keywords'
         58        SEND_VAL                                                 ~45
         59        FETCH_DIM_R                                      ~46     !6, 'keywords'
         60        SEND_VAL                                                 ~46
         61        DO_ICALL                                         $47     
         62        ADD_ARRAY_ELEMENT                                ~44     $47, 'keywords'
         63        ASSIGN_DIM                                               !8, !4
         64        OP_DATA                                                  ~44
   52    65    > > JMP                                                      ->26
         66    >   FE_FREE                                                  $23
   50    67      > JMP                                                      ->15
         68    >   FE_FREE                                                  $15
   63    69      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.2 ms | 1400 KiB | 21 Q