Пример #1
0
    {
        if (!is_numeric($value) || $value != (int) $value) {
            return 'I cannot sum that';
        }
        return array_sum(str_split(abs($value)));
    }
    $input = explode(', ', $_POST['input']);
    ?>
<table>
    <?php 
    foreach ($input as $value) {
        ?>
    <tr>
        <td><?php 
        echo $value;
        ?>
</td>
        <td><?php 
        echo sumOfDigits($value);
        ?>
</td>
    </tr>
    <?php 
    }
    ?>
</table>
<?php 
}
?>
</body>
</html>
Пример #2
0
        }
        return $sum;
    }
    $input = explode(', ', $_POST['string']);
    ?>

<table>
    <tbody>

    <?php 
    foreach ($input as $str) {
        ?>
        <tr>
            <td> <?php 
        echo htmlentities(trim($str));
        ?>
</td>
            <td> <?php 
        echo isInteger($str) ? sumOfDigits($str) : "I cannot sum that";
        ?>
</td>
        </tr>
    <?php 
    }
    ?>

    </tbody>
</table>

<?php 
}