3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dbDownloads = array( 0 => array( "name" => "Xvid_Download.txt", "userId" => 1, "torrentId" => "4e1210f2469a7078eb0ecd6ef462d16f44d99837", "id" => 1 ), 1 => array( "name" => "Lol.mp4", "userId" => 2, "torrentId" => "e3811b9539cacff680e418124272177c47477157", "id" => 2 ), 2 => array( "name" => "Ubuntu-13.04.iso", "userId" => 1, "torrentId" => "c877dcecd3b14d02c0eccfd4e67a2cee71518405", "id" => 3 ), 3 => array( "name" => "NonDownload.lol", "userId" => 2, "torrentId" => "b7687dbbh8873dcc87464gf4387g78g7gf828887", "id" => 4 ) ); $clientTorrents = array( 0 => array( "hashString" => "4e1210f2469a7078eb0ecd6ef462d16f44d99837", "name" => "Xvid_Download.txt" ), 1 => array( "hashString" => "c877dcecd3b14d02c0eccfd4e67a2cee71518405", "name" => "Ubuntu-13.04.iso" ), 2 => array( "hashString" => "b7687dbbh8873dcc87464gf4387g78g7gf828887", "torrentname" => "NonDownload.lol" ), 3 => array( "hashString" => "e3811b9539cacff680e418124272177c47477157", "torrentname" => "Lol.mp4" ) ); $merged = array(); foreach ($clientTorrents as $clientTorrent) { /** Match $dbDownload::torrentId against clientTorrent::$hashString **/ $dbDownload = array_values(array_filter($dbDownloads, function($dbDownload) use($clientTorrent) { return $dbDownload['torrentId'] === $clientTorrent['hashString']; }))[0]; var_dump($clientTorrent); var_dump("<br /><br />"); var_dump($dbDownload); var_dump("<br /><br />---------------<br />"); }
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(2) { ["hashString"]=> string(40) "4e1210f2469a7078eb0ecd6ef462d16f44d99837" ["name"]=> string(17) "Xvid_Download.txt" } string(12) "<br /><br />" array(4) { ["name"]=> string(17) "Xvid_Download.txt" ["userId"]=> int(1) ["torrentId"]=> string(40) "4e1210f2469a7078eb0ecd6ef462d16f44d99837" ["id"]=> int(1) } string(33) "<br /><br />---------------<br />" array(2) { ["hashString"]=> string(40) "c877dcecd3b14d02c0eccfd4e67a2cee71518405" ["name"]=> string(16) "Ubuntu-13.04.iso" } string(12) "<br /><br />" array(4) { ["name"]=> string(16) "Ubuntu-13.04.iso" ["userId"]=> int(1) ["torrentId"]=> string(40) "c877dcecd3b14d02c0eccfd4e67a2cee71518405" ["id"]=> int(3) } string(33) "<br /><br />---------------<br />" array(2) { ["hashString"]=> string(40) "b7687dbbh8873dcc87464gf4387g78g7gf828887" ["torrentname"]=> string(15) "NonDownload.lol" } string(12) "<br /><br />" array(4) { ["name"]=> string(15) "NonDownload.lol" ["userId"]=> int(2) ["torrentId"]=> string(40) "b7687dbbh8873dcc87464gf4387g78g7gf828887" ["id"]=> int(4) } string(33) "<br /><br />---------------<br />" array(2) { ["hashString"]=> string(40) "e3811b9539cacff680e418124272177c47477157" ["torrentname"]=> string(7) "Lol.mp4" } string(12) "<br /><br />" array(4) { ["name"]=> string(7) "Lol.mp4" ["userId"]=> int(2) ["torrentId"]=> string(40) "e3811b9539cacff680e418124272177c47477157" ["id"]=> int(2) } string(33) "<br /><br />---------------<br />"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/aMBQ3 on line 56
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/aMBQ3 on line 53
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/aMBQ3 on line 53
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/aMBQ3 on line 53
Process exited with code 255.