3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pizzas = [ ['cheese', 'tomato', 'ham', 'beef', 'pineapple'], ['bacon', 'ham', 'cheese'], ['cheese', 'tomato', 'bacon', 'chili', 'salad'], ['tomato', 'salad', 'pineapple'], ['tomato', 'beef', 'bacon'], ['cheese', 'tomato', 'bacon', 'chili', 'salad', 'anchovies'], ['tomato', 'pineapple', 'bacon', 'cheese', 'ham'], ]; $included_wish = ['cheese', 'ham', 'bacon']; $excluded_wish = ['pineapple']; $percentages = []; $wishCount = count($included_wish); foreach ($pizzas as $pizza) { if (array_intersect($excluded_wish, $pizza)) { continue; } $result[] = [ 'perc' => count(array_intersect($included_wish, $pizza)) / $wishCount, 'additional' => count(array_diff($pizza, $included_wish)), 'ingredients' => implode(', ', $pizza), ]; } usort($result, fn($a, $b) => [$b['perc'], $a['additional']] <=> [$a['perc'], $b['additional']]); foreach ($result as $row) { vprintf("wished: %.02f%%, surplus toppings: %d : %s\n", $row); }
Output for 8.0.1 - 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.5.0
wished: 1.00%, surplus toppings: 0 : bacon, ham, cheese wished: 0.67%, surplus toppings: 3 : cheese, tomato, bacon, chili, salad wished: 0.67%, surplus toppings: 4 : cheese, tomato, bacon, chili, salad, anchovies wished: 0.33%, surplus toppings: 2 : tomato, beef, bacon
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:
130.24 ms | 407 KiB | 5 Q