<?php
include('includes/header.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Ashlynn's Array Example</h1>
<!-- Form to accept multiple values -->
<form method="POST">
<label for="numbers">Enter numbers (separated by commas):</label><br>
<input type="text" id="numbers" name="numbers" required><br><br>
<input type="submit" value="Submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$inputString = $_POST['numbers'];
$numbersArray = array_map('trim', explode(',', $inputString));
// convert string values to integers
$numbersArray = array_map('intval', $numbersArray);
$sortedArray = $numbersArray; // copy original array for sorting
sort($sortedArray); // sort the array in ascending order
$maxValue = max($numbersArray); // find maximum value
$minValue = min($numbersArray); // find minimum value
$averageValue = array_sum($numbersArray) / count($numbersArray); // calculate average
$uniqueValues = array_unique($numbersArray); // get unique values
echo "<h2>Results:</h2>";
echo "<p><strong>Original Array:</strong> " . implode(', ', $numbersArray) . "</p>";
echo "<p><strong>Sorted Array:</strong> " . implode(', ', $sortedArray) . "</p>";
echo "<p><strong>Maximum Value:</strong> $maxValue</p>";
echo "<p><strong>Minimum Value:</strong> $minValue</p>";
echo "<p><strong>Average Value:</strong> $averageValue</p>";
echo "<p><strong>Unique Values:</strong> " . implode(', ', $uniqueValues) . "</p>";
}
?>
<?php
echo("<br><br>");
include('includes/footer.php');
?>
</body>
</html>