3v4l.org

run code in 300+ PHP versions simultaneously
<?php $recipes = [ 'cc' => [ 'in' => ['c' => 1], 'out' => ['cc' => 2], 'time' => 0.5, 'terminal' => true, ], 'gc' => [ 'in' => ['cc' => 1.5, 'i' => 1,], 'out' => ['gc' => 1], 'time' => 0.5, 'terminal' => false, ], 'rc' => [ 'in' => ['gc' => 2, 'p' => 2, 'cc' => 2], 'out' => ['rc' => 1], 'time' => 6, 'terminal' => false, ], 'bc' => [ 'in' => ['gc' => 20, 'rc' => 2], 'out' => ['bc' => 1], 'time' => 10, 'terminal' => false, ], ]; function solveFor($recipes, $type, $numAssemblers, $requirements = []) { if ( $recipes[$type]['terminal']) { foreach($recipes[$type]['in'] as $k => $v) { if (! array_key_exists($type, $requirements)) { $requirements[$type] = 0; } $perMinute = 60 / $recipes[$type]['time']; $requirements[$k] = $requirements[$k] + ($numAssemblers * $v * $perMinute); return $requirements; } } else { foreach($recipes[$type]['in'] as $k => $v) { $depReq = solveFor($recipes, $k, 1, $requirements); foreach ($depReq as $k2 => $v2) { $requirements[$k2] += $v2; } } return $requirements; } } print_r( solveFor($recipes, 'cc', 4, []) );
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "c" in /in/mkSng on line 39 Array ( [cc] => 0 [c] => 480 )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "c" in /in/mkSng on line 39 Array ( [cc] => 0 [c] => 480 )
Output for 7.2.11, 7.3.24 - 7.3.31, 7.4.12 - 7.4.33
Notice: Undefined index: c in /in/mkSng on line 39 Array ( [cc] => 0 [c] => 480 )
Output for 7.3.32 - 7.3.33
Array ( [cc] => 0 [c] => 480 )

preferences:
113.04 ms | 401 KiB | 116 Q