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>
Output for git.master, git.master_jit, rfc.property-hooks
<script type="application/ld+json"> { "@context": "http:\/\/schema.org", "@type": "Product", "aggregateRating": [ { "@type": "AggregateRating", "ratingValue": 1, "reviewCount": 100 } ], "description": "How do I not break json", "name": "As above...", "image": "http:\/\/...\/thumb.jpg", "review": [ { "@type": "Review", "author": "Lawrence Cherone", "datePublished": "11\/11\/17 00:00:00", "description": "", "name": "Lawrence Cherone", "reviewRating": { "@type": "Rating", "bestRating": "5", "ratingValue": 1, "worstRating": "1" } } ] }</script>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
30.35 ms | 407 KiB | 5 Q