3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlstr = '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <Xiami> <ArtistID>179</ArtistID> <ArtistName>Band 1</ArtistName> <XiamiID>9dl4gN1c745</XiamiID> <Streaming>246</Streaming> <Fans>84</Fans> <TotalComments>1992</TotalComments> <AllSongs> <Songs> <SongID>8ILroS998dc</SongID> <SongName>Song 1</SongName> <SongComments>9223</SongComments> </Songs> <Songs> <SongID>8ILLD61a351</SongID> <SongName>Song 2</SongName> <SongComments>7221</SongComments> </Songs> <Songs> <SongID>mTnf0L5d6b9</SongID> <SongName>Song 3</SongName> <SongComments>21212</SongComments> </Songs> <Songs> <SongID>xOd2YIc7f69</SongID> <SongName>Song 4</SongName> <SongComments>422</SongComments> </Songs> <Songs> <SongID>mTmg866314c</SongID> <SongName>Song 5</SongName> <SongComments>81211</SongComments> </Songs> </AllSongs> </Xiami> </rss>'; function popular_songs($Artist) { $Songs = $Artist->xpath('//Songs'); usort($Songs, function ($a, $b) { return $b->SongComments - $a->SongComments; }); return array_slice($Songs, 0, 3); } $xml = simplexml_load_string($xmlstr); foreach($xml->children() as $Artist) { $ArtistName = $Artist->ArtistName; $Streaming = $Artist->Streaming; $Fans = $Artist->Fans; $SongsArrays = $Artist->AllSongs; $SongsCount = $Artist->AllSongs->Songs->count(); $TotalComments = array_reduce($Artist->xpath('//SongComments'), function ($c, $v) { return $c + $v; }, 0); echo $TotalComments . PHP_EOL; $PopularSongs = popular_songs($Artist); print_r($PopularSongs); }
Output for git.master, git.master_jit, rfc.property-hooks
119289 Array ( [0] => SimpleXMLElement Object ( [SongID] => mTmg866314c [SongName] => Song 5 [SongComments] => 81211 ) [1] => SimpleXMLElement Object ( [SongID] => mTnf0L5d6b9 [SongName] => Song 3 [SongComments] => 21212 ) [2] => SimpleXMLElement Object ( [SongID] => 8ILroS998dc [SongName] => Song 1 [SongComments] => 9223 ) )

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:
160.91 ms | 406 KiB | 5 Q