my code stock.com

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

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

Повинно рахувати суми елементів масиву. 2х, 3х,4х.

Snippet options

Download: Download snippet as 1.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 = 332;

for ($i = 0; $i < $incount; $i++) {
    for ($j = 0; $j < $incount; $j++) {
        for ($k = 0; $k < $incount; $k++){
            for($p = 0; $p < $incount; $p++) {
                if ($input[$i] + $input[$j] + $input[$k] + $input[$p] == $d) {
                    $output[$i] = $output[$j] = $output[$k] = $output[$p] = 1;
                    break;
                } else {


                    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;
                            break;
                        }
                    }}}}}}



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.