3v4l.org

run code in 300+ PHP versions simultaneously
<?php function wp_create_links( $link_data ) { $links = array(); if ( isset( $link_data ) && is_array( $link_data ) ) { foreach ( $link_data as $key => $link ) { $attributes = array(); if ( isset( $link['attributes'] ) && is_array( $link['attributes'] ) ) { $attributes = $link['attributes']; } // URL check. if ( empty( $link['url'] ) || ! is_string( $link['url'] ) || '' === trim( $link['url'] ) ) { continue; } // Label check. if ( empty( $link['label'] ) || ! is_string( $link['label'] ) || '' === trim( $link['label'] ) ) { continue; } // Current check. if ( ! empty( $link['is_current'] ) && true === $link['is_current'] ) { $attributes['aria-current'] = 'page'; if ( empty( $attributes['class'] ) ) { $attributes['class'] = 'current'; } else { $attributes['class'] .= ' current'; } } // Collapse attributes to attribute="value" or boolean attributes. $attributes = array_map( function( $attribute, $value ) { // Mark invalid/empty attributes for removal. if ( empty( $attribute ) || ! is_string( $attribute ) ) { return false; } // Convert `int` and `float` values to `string`. if ( is_int( $value ) || is_float( $value ) ) { $value = (string) $value; } // Mark non-string values for removal. if ( ! is_string( $value ) ) { return false; } // On an empty `value`, assume this is a boolean attribute. if ( empty( $value ) ) { return $attribute; } return sprintf( '%s="%s"', $attribute, $value ); }, array_keys( $attributes ), array_values( $attributes ) ); // Clean up attributes. $attributes = array_filter( $attributes ); // Generate link. $links[ $key ] = sprintf( '<a href="%s"%s>%s</a>', $link['url'], ! empty( $attributes ) ? ' ' . implode( ' ', $attributes ) : '', $link['label'] ); } } return $links; } // Usage $links_data = array( 'author-link' => array( 'url' => 'https://example.org', 'label' => 'My Example Link', 'attributes' => array( 'class' => 'menu-link', 'rel' => 'author me', ), 'is_current' => true, ), 'external-link' => array( 'url' => 'https://example.com', 'label' => 'My Other Example Link', 'attributes' => array( 'class' => 'menu-link', 'rel' => 'external noreferer', ), ), ); $links = wp_create_links( $links_data ); // Want to wrap them with the key as the class? $menu = '<ul class="menu">'; foreach ( $links as $key => $link ) { $menu .= sprintf( '<li class="menu-item %s">%s</li>', $key, $link ); } $menu .= '</ul>'; echo $menu;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/KutDg
function name:  (null)
number of ops:  20
compiled vars:  !0 = $links_data, !1 = $links, !2 = $menu, !3 = $link, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   ASSIGN                                                   !0, <array>
  105     1        INIT_FCALL                                               'wp_create_links'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
  108     5        ASSIGN                                                   !2, '%3Cul+class%3D%22menu%22%3E'
  109     6      > FE_RESET_R                                       $9      !1, ->16
          7    > > FE_FETCH_R                                       ~10     $9, !3, ->16
          8    >   ASSIGN                                                   !4, ~10
  110     9        INIT_FCALL                                               'sprintf'
         10        SEND_VAL                                                 '%3Cli+class%3D%22menu-item+%25s%22%3E%25s%3C%2Fli%3E'
         11        SEND_VAR                                                 !4
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $12     
         14        ASSIGN_OP                                     8          !2, $12
  109    15      > JMP                                                      ->7
         16    >   FE_FREE                                                  $9
  112    17        ASSIGN_OP                                     8          !2, '%3C%2Ful%3E'
  114    18        ECHO                                                     !2
  115    19      > RETURN                                                   1

Function wp_create_links:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 105
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 104
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 104
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 47) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 34
2 jumps found. (Code = 47) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
2 jumps found. (Code = 47) Position 1 = 41, Position 2 = 47
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 49
2 jumps found. (Code = 46) Position 1 = 52, Position 2 = 55
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 65
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 63
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 96
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 96
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 96
Branch analysis from position: 89
Branch analysis from position: 96
Branch analysis from position: 65
Branch analysis from position: 55
Branch analysis from position: 47
Branch analysis from position: 40
Branch analysis from position: 32
Branch analysis from position: 25
Branch analysis from position: 19
Branch analysis from position: 16
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
Branch analysis from position: 105
Branch analysis from position: 6
filename:       /in/KutDg
function name:  wp_create_links
number of ops:  107
compiled vars:  !0 = $link_data, !1 = $links, !2 = $link, !3 = $key, !4 = $attributes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    6     2        ISSET_ISEMPTY_CV                                 ~6      !0
          3      > JMPZ_EX                                          ~6      ~6, ->6
          4    >   TYPE_CHECK                                  128  ~7      !0
          5        BOOL                                             ~6      ~7
          6    > > JMPZ                                                     ~6, ->105
    7     7    > > FE_RESET_R                                       $8      !0, ->104
          8    > > FE_FETCH_R                                       ~9      $8, !2, ->104
          9    >   ASSIGN                                                   !3, ~9
    8    10        ASSIGN                                                   !4, <array>
   10    11        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !2, 'attributes'
         12      > JMPZ_EX                                          ~12     ~12, ->16
         13    >   FETCH_DIM_R                                      ~13     !2, 'attributes'
         14        TYPE_CHECK                                  128  ~14     ~13
         15        BOOL                                             ~12     ~14
         16    > > JMPZ                                                     ~12, ->19
   11    17    >   FETCH_DIM_R                                      ~15     !2, 'attributes'
         18        ASSIGN                                                   !4, ~15
   15    19    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~17     !2, 'url'
         20      > JMPNZ_EX                                         ~17     ~17, ->25
         21    >   FETCH_DIM_R                                      ~18     !2, 'url'
         22        TYPE_CHECK                                   64  ~19     ~18
         23        BOOL_NOT                                         ~20     ~19
         24        BOOL                                             ~17     ~20
         25    > > JMPNZ_EX                                         ~17     ~17, ->32
         26    >   INIT_FCALL                                               'trim'
         27        FETCH_DIM_R                                      ~21     !2, 'url'
         28        SEND_VAL                                                 ~21
         29        DO_ICALL                                         $22     
         30        IS_IDENTICAL                                     ~23     $22, ''
         31        BOOL                                             ~17     ~23
         32    > > JMPZ                                                     ~17, ->34
   16    33    > > JMP                                                      ->8
   20    34    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~24     !2, 'label'
         35      > JMPNZ_EX                                         ~24     ~24, ->40
         36    >   FETCH_DIM_R                                      ~25     !2, 'label'
         37        TYPE_CHECK                                   64  ~26     ~25
         38        BOOL_NOT                                         ~27     ~26
         39        BOOL                                             ~24     ~27
         40    > > JMPNZ_EX                                         ~24     ~24, ->47
         41    >   INIT_FCALL                                               'trim'
         42        FETCH_DIM_R                                      ~28     !2, 'label'
         43        SEND_VAL                                                 ~28
         44        DO_ICALL                                         $29     
         45        IS_IDENTICAL                                     ~30     $29, ''
         46        BOOL                                             ~24     ~30
         47    > > JMPZ                                                     ~24, ->49
   21    48    > > JMP                                                      ->8
   25    49    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~31     !2, 'is_current'
         50        BOOL_NOT                                         ~32     ~31
         51      > JMPZ_EX                                          ~32     ~32, ->55
         52    >   FETCH_DIM_R                                      ~33     !2, 'is_current'
         53        TYPE_CHECK                                    8  ~34     ~33
         54        BOOL                                             ~32     ~34
         55    > > JMPZ                                                     ~32, ->65
   26    56    >   ASSIGN_DIM                                               !4, 'aria-current'
         57        OP_DATA                                                  'page'
   28    58        ISSET_ISEMPTY_DIM_OBJ                         1          !4, 'class'
         59      > JMPZ                                                     ~36, ->63
   29    60    >   ASSIGN_DIM                                               !4, 'class'
         61        OP_DATA                                                  'current'
         62      > JMP                                                      ->65
   31    63    >   ASSIGN_DIM_OP                .=               8          !4, 'class'
         64        OP_DATA                                                  '+current'
   36    65    >   INIT_FCALL                                               'array_map'
   37    66        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FKutDg%3A37%240'
   63    67        SEND_VAL                                                 ~39
   64    68        INIT_FCALL                                               'array_keys'
         69        SEND_VAR                                                 !4
         70        DO_ICALL                                         $40     
         71        SEND_VAR                                                 $40
   65    72        INIT_FCALL                                               'array_values'
         73        SEND_VAR                                                 !4
         74        DO_ICALL                                         $41     
         75        SEND_VAR                                                 $41
         76        DO_ICALL                                         $42     
   36    77        ASSIGN                                                   !4, $42
   69    78        INIT_FCALL                                               'array_filter'
         79        SEND_VAR                                                 !4
         80        DO_ICALL                                         $44     
         81        ASSIGN                                                   !4, $44
   72    82        INIT_FCALL                                               'sprintf'
   73    83        SEND_VAL                                                 '%3Ca+href%3D%22%25s%22%25s%3E%25s%3C%2Fa%3E'
   74    84        FETCH_DIM_R                                      ~47     !2, 'url'
         85        SEND_VAL                                                 ~47
   75    86        ISSET_ISEMPTY_CV                                 ~48     !4
         87        BOOL_NOT                                         ~49     ~48
         88      > JMPZ                                                     ~49, ->96
         89    >   INIT_FCALL                                               'implode'
         90        SEND_VAL                                                 '+'
         91        SEND_VAR                                                 !4
         92        DO_ICALL                                         $50     
         93        CONCAT                                           ~51     '+', $50
         94        QM_ASSIGN                                        ~52     ~51
         95      > JMP                                                      ->97
         96    >   QM_ASSIGN                                        ~52     ''
         97    >   SEND_VAL                                                 ~52
   76    98        FETCH_DIM_R                                      ~53     !2, 'label'
         99        SEND_VAL                                                 ~53
        100        DO_ICALL                                         $54     
   72   101        ASSIGN_DIM                                               !1, !3
   76   102        OP_DATA                                                  $54
    7   103      > JMP                                                      ->8
        104    >   FE_FREE                                                  $8
   81   105    > > RETURN                                                   !1
   82   106*     > RETURN                                                   null

End of function wp_create_links

Function %00%7Bclosure%7D%2Fin%2FKutDg%3A37%240:
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 = 47) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/KutDg
function name:  {closure}
number of ops:  30
compiled vars:  !0 = $attribute, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        ISSET_ISEMPTY_CV                                 ~2      !0
          3      > JMPNZ_EX                                         ~2      ~2, ->7
          4    >   TYPE_CHECK                                   64  ~3      !0
          5        BOOL_NOT                                         ~4      ~3
          6        BOOL                                             ~2      ~4
          7    > > JMPZ                                                     ~2, ->9
   40     8    > > RETURN                                                   <false>
   44     9    >   TYPE_CHECK                                   16  ~5      !1
         10      > JMPNZ_EX                                         ~5      ~5, ->13
         11    >   TYPE_CHECK                                   32  ~6      !1
         12        BOOL                                             ~5      ~6
         13    > > JMPZ                                                     ~5, ->16
   45    14    >   CAST                                          6  ~7      !1
         15        ASSIGN                                                   !1, ~7
   49    16    >   TYPE_CHECK                                   64  ~9      !1
         17        BOOL_NOT                                         ~10     ~9
         18      > JMPZ                                                     ~10, ->20
   50    19    > > RETURN                                                   <false>
   54    20    >   ISSET_ISEMPTY_CV                                         !1
         21      > JMPZ                                                     ~11, ->23
   55    22    > > RETURN                                                   !0
   58    23    >   INIT_FCALL                                               'sprintf'
   59    24        SEND_VAL                                                 '%25s%3D%22%25s%22'
   60    25        SEND_VAR                                                 !0
   61    26        SEND_VAR                                                 !1
         27        DO_ICALL                                         $12     
         28      > RETURN                                                   $12
   63    29*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FKutDg%3A37%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
104.72 ms | 442 KiB | 21 Q