my code stock.com

Ростислав Тернущак

2.
by Ростислав Тернущак

Рахує суму 2х і 3х елементів .

Snippet options

Download: Download snippet as 2.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php
$input = array('2', '7', '11', '21', '42', '89', '180', '354');
$incount = count($input);
$output = array_fill(0, $incount, 0);
$d = 110;

for ($i = 0; $i < $incount; $i++) {
    for ($j = 0; $j < $incount; $j++) {
        for ($k = 0; $k < $incount; $k++){
            if ($input[$i] + $input[$j]+ $input[$k] == $d) {
                $output[$i] = $output[$j] = $output[$k]= 1;
                break;
            } else {
                if ($input[$i] + $input[$j] == $d){
                    $output[$i] = $output[$j] = 1;
                }
            }
        }
    }
}
echo "<br>";
echo implode ('', $output);
echo "<br>";
?>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.