3v4l.org

run code in 300+ PHP versions simultaneously
<?php // your arbitrary vars $rating = 1; $review_total = 100; $description = 'How do I not break json'; $heading_title = 'As above...'; $thumb = 'http://.../thumb.jpg'; $json = [ '@context' => 'http://schema.org', '@type' => 'Product', 'aggregateRating' => [ [ '@type' => 'AggregateRating', 'ratingValue' => $rating, 'reviewCount' => $review_total, ] ], 'description' => $description, 'name' => $heading_title, 'image' => $thumb, 'review' => [], ]; // query reviews from db $reviews = [ [ 'author' => 'Lawrence Cherone', 'date_added' => '11/11/17 00:00:00', 'text' => 'You should instead use json_encode', 'rating' => 1 ], ]; foreach ($reviews as $review) { $json['review'][] = [ '@type' => 'Review', 'author' => $review['author'], 'datePublished' => $review['date_added'], 'description' => '', 'name' => $review['author'], 'reviewRating' => [ '@type' => 'Rating', 'bestRating' => '5', 'ratingValue' => $review['rating'], 'worstRating' => '1', ], ]; } ?> <script type="application/ld+json"> <?= json_encode($json, JSON_PRETTY_PRINT) ?> </script>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 38
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 38
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/u0Fd3
function name:  (null)
number of ops:  47
compiled vars:  !0 = $rating, !1 = $review_total, !2 = $description, !3 = $heading_title, !4 = $thumb, !5 = $json, !6 = $reviews, !7 = $review
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 1
    4     1        ASSIGN                                                   !1, 100
    5     2        ASSIGN                                                   !2, 'How+do+I+not+break+json'
    6     3        ASSIGN                                                   !3, 'As+above...'
    7     4        ASSIGN                                                   !4, 'http%3A%2F%2F...%2Fthumb.jpg'
   10     5        INIT_ARRAY                                       ~13     'http%3A%2F%2Fschema.org', '%40context'
   11     6        ADD_ARRAY_ELEMENT                                ~13     'Product', '%40type'
   14     7        INIT_ARRAY                                       ~14     'AggregateRating', '%40type'
   15     8        ADD_ARRAY_ELEMENT                                ~14     !0, 'ratingValue'
   16     9        ADD_ARRAY_ELEMENT                                ~14     !1, 'reviewCount'
         10        INIT_ARRAY                                       ~15     ~14
         11        ADD_ARRAY_ELEMENT                                ~13     ~15, 'aggregateRating'
   19    12        ADD_ARRAY_ELEMENT                                ~13     !2, 'description'
   20    13        ADD_ARRAY_ELEMENT                                ~13     !3, 'name'
   21    14        ADD_ARRAY_ELEMENT                                ~13     !4, 'image'
   10    15        ADD_ARRAY_ELEMENT                                ~13     <array>, 'review'
    9    16        ASSIGN                                                   !5, ~13
   26    17        ASSIGN                                                   !6, <array>
   35    18      > FE_RESET_R                                       $18     !6, ->38
         19    > > FE_FETCH_R                                               $18, !7, ->38
   37    20    >   INIT_ARRAY                                       ~21     'Review', '%40type'
   38    21        FETCH_DIM_R                                      ~22     !7, 'author'
         22        ADD_ARRAY_ELEMENT                                ~21     ~22, 'author'
   39    23        FETCH_DIM_R                                      ~23     !7, 'date_added'
         24        ADD_ARRAY_ELEMENT                                ~21     ~23, 'datePublished'
   40    25        ADD_ARRAY_ELEMENT                                ~21     '', 'description'
   41    26        FETCH_DIM_R                                      ~24     !7, 'author'
         27        ADD_ARRAY_ELEMENT                                ~21     ~24, 'name'
   43    28        INIT_ARRAY                                       ~25     'Rating', '%40type'
   44    29        ADD_ARRAY_ELEMENT                                ~25     '5', 'bestRating'
   45    30        FETCH_DIM_R                                      ~26     !7, 'rating'
         31        ADD_ARRAY_ELEMENT                                ~25     ~26, 'ratingValue'
   46    32        ADD_ARRAY_ELEMENT                                ~25     '1', 'worstRating'
         33        ADD_ARRAY_ELEMENT                                ~21     ~25, 'reviewRating'
   36    34        FETCH_DIM_W                                      $19     !5, 'review'
         35        ASSIGN_DIM                                               $19
   46    36        OP_DATA                                                  ~21
   35    37      > JMP                                                      ->19
         38    >   FE_FREE                                                  $18
   51    39        ECHO                                                     '%0A%3Cscript+type%3D%22application%2Fld%2Bjson%22%3E%0A'
   53    40        INIT_FCALL                                               'json_encode'
         41        SEND_VAR                                                 !5
         42        SEND_VAL                                                 128
         43        DO_ICALL                                         $27     
         44        ECHO                                                     $27
   54    45        ECHO                                                     '%3C%2Fscript%3E'
         46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.06 ms | 1007 KiB | 14 Q