<?php
function getProductOfAllOtherElements($numbers) {
$products = [];
for ($i = 0; $i < count($numbers); $i++) {
$products[$i] = 1;
for ($j = 0; $j < count($numbers); $j++) {
if ($i != $j) {
$products[$i] = $products[$i] * $numbers[$j];
}
}
}
return $products;
}
function printSeparator($size = 64) {
echo str_repeat('-', $size) . "\n";
}
function evaluate($input, $expectedOutput) {
$result = getProductOfAllOtherElements($input);
echo "Input: " . $input . json_encode($input) . "\n";
echo "ExpectedOutput: " . json_encode($expectedOutput) . "\n";
echo "Result: " . json_encode($result) . "\n";;
echo "IsCorrect: " . (json_encode($result) == json_encode($expectedOutput) ? 'True' : 'False') . "\n";;
}
printSeparator();
evaluate([3, 2, 1], [2, 3, 6]);
printSeparator();
evaluate([1, 2, 3, 4, 5], [120, 60, 40, 30, 24]);
printSeparator();
To embed this project on your website, copy the following code and paste it into your website's HTML: