3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Created by PhpStorm. * User: efik * Date: 21.09.15 * Time: 13:28 */ $podcasts = []; foreach (range(1, 150) as $index) { $podcasts[] = [ "id" => $index * mt_rand(1, 4), "title" => "Song - " . $index, "time" => $index, "License" => "MIT", ]; } arsort($podcasts); $dom = new DOMDocument("1.0", "UTF-8"); $podcastDOM = $dom->createElement("podcast"); foreach ($podcasts as $podcast) { $item = $dom->createElement('song'); foreach ($podcast as $key => $value) { if ($key !== "title") { $currentKey = $dom->createAttribute($key); $currentKey->appendChild($dom->createTextNode($value)); } else { $item->appendChild($dom->createTextNode($value)); } $item->appendChild($currentKey); $podcastDOM->appendChild($item); } } $dom->appendChild($podcastDOM); header("Content-Type: text/xml"); echo $dom->saveXML();

preferences:
24.01 ms | 402 KiB | 5 Q