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 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
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 ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
169.44 ms | 408 KiB | 5 Q