3v4l.org

run code in 300+ PHP versions simultaneously
<?php function item_by_value($array,$key,$value) { // returns FIRST matching element only, presumes ID if ((!is_array($array)) || empty($key) || empty($value)) return false; for ($i=0; $i < count($array); $i++) { $item = (array) $array[$i]; if ($item[$key] == $value) { return $array[$i]; break; } } return null; } function article_link($article,$articles) { if (is_null($article) || !is_object($article)) {return '';} if ($article->parentPage == 'self') { return '/'.$article->id; } else { $parent = item_by_value($articles,'id',$article->parentPage); // if null presume section? return is_null($parent) ? '/'.$article->parentPage.'/'.$article->id : article_link($parent->id,$articles).'/'.$article->id; } } $articles = json_decode('{"articles":[{"id":"about","title":"Significant Object","bodyHtml":"about-main.html","parentPage":"self","banner":"stock"},{"id":"workshops","title":"Workshops","bodyHtml":"workshops.html","parentPage":"self","banner":null},{"id":"making","title":"Making","bodyHtml":"making.html","parentPage":"self"},{"id":"the-lion-the-witch-and","title":"The Lion, The Witch and The Wardrobe","bodyHtml":"the-lion-the-witch.html","parentPage":"past"},{"id":"circus-1903","title":"Circus 1903","bodyHtml":"circus-1903.html","parentPage":"current","banner":"stock"},{"id":"dissonance","title":"Dissonance","bodyHtml":"dissonance.html","parentPage":"current"},{"id":"handspring-uk","title":"Handspring UK","bodyHtml":"handspring-uk.html","parentPage":"past","banner":"stock"},{"id":"james-ii","title":"James II","bodyHtml":"james-ii.html","parentPage":"past"},{"id":"die-bruder-lowenherz","title":"Die Brüder Löwenherz (The Brothers Lionheart)","bodyHtml":"lowenherz.html","parentPage":"past"},{"id":"newman","title":"Newman","bodyHtml":"newman.html","parentPage":"past"},{"id":"stiller","title":"Stiller","bodyHtml":"stiller.html","parentPage":"past"},{"id":"the-loris","title":"The Loris","bodyHtml":"the-loris.html","parentPage":"past"},{"id":"reviews-of-stiller","title":"Press Reviews of Stiller","bodyHtml":"reviews-of-stiller.html","parentPage":"stiller","banner":"none"},{"id":"jubilee-salute","title":"Jubilee Salute","bodyHtml":"jubilee-salute-handspring-UK.html","parentPage":"past"},{"id":"crow","title":"Crow","bodyHtml":"crow.html","parentPage":"past"}]}'); $test = $articles->articles[10]; $array = $articles->articles; echo article_link($test,$array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VEFpO
function name:  (null)
number of ops:  15
compiled vars:  !0 = $articles, !1 = $test, !2 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%7B%22articles%22%3A%5B%7B%22id%22%3A%22about%22%2C%22title%22%3A%22Significant+Object%22%2C%22bodyHtml%22%3A%22about-main.html%22%2C%22parentPage%22%3A%22self%22%2C%22banner%22%3A%22stock%22%7D%2C%7B%22id%22%3A%22workshops%22%2C%22title%22%3A%22Workshops%22%2C%22bodyHtml%22%3A%22workshops.html%22%2C%22parentPage%22%3A%22self%22%2C%22banner%22%3Anull%7D%2C%7B%22id%22%3A%22making%22%2C%22title%22%3A%22Making%22%2C%22bodyHtml%22%3A%22making.html%22%2C%22parentPage%22%3A%22self%22%7D%2C%7B%22id%22%3A%22the-lion-the-witch-and%22%2C%22title%22%3A%22The+Lion%2C+The+Witch+and+The+Wardrobe%22%2C%22bodyHtml%22%3A%22the-lion-the-witch.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22circus-1903%22%2C%22title%22%3A%22Circus+1903%22%2C%22bodyHtml%22%3A%22circus-1903.html%22%2C%22parentPage%22%3A%22current%22%2C%22banner%22%3A%22stock%22%7D%2C%7B%22id%22%3A%22dissonance%22%2C%22title%22%3A%22Dissonance%22%2C%22bodyHtml%22%3A%22dissonance.html%22%2C%22parentPage%22%3A%22current%22%7D%2C%7B%22id%22%3A%22handspring-uk%22%2C%22title%22%3A%22Handspring+UK%22%2C%22bodyHtml%22%3A%22handspring-uk.html%22%2C%22parentPage%22%3A%22past%22%2C%22banner%22%3A%22stock%22%7D%2C%7B%22id%22%3A%22james-ii%22%2C%22title%22%3A%22James+II%22%2C%22bodyHtml%22%3A%22james-ii.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22die-bruder-lowenherz%22%2C%22title%22%3A%22Die+Br%C3%BCder+L%C3%B6wenherz+%28The+Brothers+Lionheart%29%22%2C%22bodyHtml%22%3A%22lowenherz.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22newman%22%2C%22title%22%3A%22Newman%22%2C%22bodyHtml%22%3A%22newman.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22stiller%22%2C%22title%22%3A%22Stiller%22%2C%22bodyHtml%22%3A%22stiller.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22the-loris%22%2C%22title%22%3A%22The+Loris%22%2C%22bodyHtml%22%3A%22the-loris.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22reviews-of-stiller%22%2C%22title%22%3A%22Press+Reviews+of+Stiller%22%2C%22bodyHtml%22%3A%22reviews-of-stiller.html%22%2C%22parentPage%22%3A%22stiller%22%2C%22banner%22%3A%22none%22%7D%2C%7B%22id%22%3A%22jubilee-salute%22%2C%22title%22%3A%22Jubilee+Salute%22%2C%22bodyHtml%22%3A%22jubilee-salute-handspring-UK.html%22%2C%22parentPage%22%3A%22past%22%7D%2C%7B%22id%22%3A%22crow%22%2C%22title%22%3A%22Crow%22%2C%22bodyHtml%22%3A%22crow.html%22%2C%22parentPage%22%3A%22past%22%7D%5D%7D'
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !0, $3
   29     4        FETCH_OBJ_R                                      ~5      !0, 'articles'
          5        FETCH_DIM_R                                      ~6      ~5, 10
          6        ASSIGN                                                   !1, ~6
   30     7        FETCH_OBJ_R                                      ~8      !0, 'articles'
          8        ASSIGN                                                   !2, ~8
   31     9        INIT_FCALL                                               'article_link'
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $10     
         13        ECHO                                                     $10
         14      > RETURN                                                   1

Function item_by_value:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 15
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 15
Branch analysis from position: 28
Branch analysis from position: 15
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/VEFpO
function name:  item_by_value
number of ops:  30
compiled vars:  !0 = $array, !1 = $key, !2 = $value, !3 = $i, !4 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        TYPE_CHECK                                  128  ~5      !0
          4        BOOL_NOT                                         ~6      ~5
          5      > JMPNZ_EX                                         ~6      ~6, ->8
          6    >   ISSET_ISEMPTY_CV                                 ~7      !1
          7        BOOL                                             ~6      ~7
          8    > > JMPNZ_EX                                         ~6      ~6, ->11
          9    >   ISSET_ISEMPTY_CV                                 ~8      !2
         10        BOOL                                             ~6      ~8
         11    > > JMPZ                                                     ~6, ->13
         12    > > RETURN                                                   <false>
    6    13    >   ASSIGN                                                   !3, 0
         14      > JMP                                                      ->25
    7    15    >   FETCH_DIM_R                                      ~10     !0, !3
         16        CAST                                          7  ~11     ~10
         17        ASSIGN                                                   !4, ~11
    8    18        FETCH_DIM_R                                      ~13     !4, !1
         19        IS_EQUAL                                                 !2, ~13
         20      > JMPZ                                                     ~14, ->24
    9    21    >   FETCH_DIM_R                                      ~15     !0, !3
         22      > RETURN                                                   ~15
   10    23*       JMP                                                      ->28
    6    24    >   PRE_INC                                                  !3
         25    >   COUNT                                            ~17     !0
         26        IS_SMALLER                                               !3, ~17
         27      > JMPNZ                                                    ~18, ->15
   13    28    > > RETURN                                                   null
   14    29*     > RETURN                                                   null

End of function item_by_value

Function article_link:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/VEFpO
function name:  article_link
number of ops:  44
compiled vars:  !0 = $article, !1 = $articles, !2 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        TYPE_CHECK                                    2  ~3      !0
          3      > JMPNZ_EX                                         ~3      ~3, ->7
          4    >   TYPE_CHECK                                  256  ~4      !0
          5        BOOL_NOT                                         ~5      ~4
          6        BOOL                                             ~3      ~5
          7    > > JMPZ                                                     ~3, ->9
          8    > > RETURN                                                   ''
   18     9    >   FETCH_OBJ_R                                      ~6      !0, 'parentPage'
         10        IS_EQUAL                                                 ~6, 'self'
         11      > JMPZ                                                     ~7, ->16
   19    12    >   FETCH_OBJ_R                                      ~8      !0, 'id'
         13        CONCAT                                           ~9      '%2F', ~8
         14      > RETURN                                                   ~9
         15*       JMP                                                      ->43
   22    16    >   INIT_FCALL                                               'item_by_value'
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 'id'
         19        FETCH_OBJ_R                                      ~10     !0, 'parentPage'
         20        SEND_VAL                                                 ~10
         21        DO_FCALL                                      0  $11     
         22        ASSIGN                                                   !2, $11
   23    23        TYPE_CHECK                                    2          !2
         24      > JMPZ                                                     ~13, ->32
         25    >   FETCH_OBJ_R                                      ~14     !0, 'parentPage'
         26        CONCAT                                           ~15     '%2F', ~14
         27        CONCAT                                           ~16     ~15, '%2F'
         28        FETCH_OBJ_R                                      ~17     !0, 'id'
         29        CONCAT                                           ~18     ~16, ~17
         30        QM_ASSIGN                                        ~19     ~18
         31      > JMP                                                      ->42
         32    >   INIT_FCALL_BY_NAME                                       'article_link'
         33        CHECK_FUNC_ARG                                           
         34        FETCH_OBJ_FUNC_ARG                               $20     !2, 'id'
         35        SEND_FUNC_ARG                                            $20
         36        SEND_VAR_EX                                              !1
         37        DO_FCALL                                      0  $21     
         38        CONCAT                                           ~22     $21, '%2F'
         39        FETCH_OBJ_R                                      ~23     !0, 'id'
         40        CONCAT                                           ~24     ~22, ~23
         41        QM_ASSIGN                                        ~19     ~24
         42    > > RETURN                                                   ~19
   25    43*     > RETURN                                                   null

End of function article_link

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
187.34 ms | 1411 KiB | 17 Q