This commit is contained in:
3p01
2025-12-04 09:30:07 +01:00
parent bdbd6c2386
commit 7b5fbb9d8b
4 changed files with 428 additions and 39 deletions

View File

@@ -44,19 +44,39 @@
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n = htmlspecialchars($_POST['n']);
$m = htmlspecialchars($_POST['m']);
(int)$values = explode(',', htmlspecialchars($_POST['values']));
$nInput = htmlspecialchars($_POST['n']);
$mInput = htmlspecialchars($_POST['m']);
$valuesInput = htmlspecialchars($_POST['values']);
$isValidDimensions = is_numeric($nInput) && is_numeric($mInput) &&
(int)$nInput == $nInput && (int)$mInput == $mInput &&
(int)$nInput > 0 && (int)$nInput <= 100 &&
(int)$mInput > 0 && (int)$mInput <= 100;
$n = (int)$nInput;
$m = (int)$mInput;
$values = array_map('trim', explode(',', $valuesInput));
echo '<div class="box">';
$count = count($values);
$isCountValid = $count === ($n*$m);
$areAllValuesValid = true;
for ($i = 0; $i < $n*$m; $i++) {
$values[$i] = (int)$values[$i];
if (!is_numeric($values[$i]) || !is_int($values[$i])) { $areAllValuesValid = false; }
for ($i = 0; $i < $count; $i++) {
if (!is_numeric($values[$i])) {
$areAllValuesValid = false;
} else {
$values[$i] = (float)$values[$i];
}
}
$values2d = array_chunk($values, $m);
if ($areAllValuesValid && $n <= 100 && $m <= 100) {
if ($isValidDimensions && $isCountValid && $areAllValuesValid) {
$values2d = array_chunk($values, $m);
echo "Wymiary tablicy: n = $n, m = $m<br>";
echo "Wprowadzone liczbe: ";
echo "Wprowadzone liczby: ";
echo implode(', ', $values);
echo "<br>Tablica $n x $m:";
echo '<table>';
@@ -68,12 +88,10 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '</tr>';
}
echo '</table>';
} else {
echo 'Dane wejściowe nie są poprawne! Sprawdź wymiary, liczbę wartości lub czy wszystkie są liczbami.';
}
else {
echo 'Liczby nie są poprawne!';
}
echo '</div>';
}
?>
</body>