Select Your Favorite Salon Services
CODE FOLLOWS
<?php
include('includes/header.php');
error_reporting(E_ALL);
?>
<h1>Select Your Favorite Salon Services</h1>
<form method="post">
<input type="checkbox" name="services[]" value="Haircut"> Haircut<br>
<input type="checkbox" name="services[]" value="Manicure"> Manicure<br>
<input type="checkbox" name="services[]" value="Pedicure"> Pedicure<br>
<input type="checkbox" name="services[]" value="Facial"> Facial<br>
<input type="checkbox" name="services[]" value="Massage"> Massage<br>
<input type="checkbox" name="services[]" value="Hair Coloring"> Hair Coloring<br>
<input type="checkbox" name="services[]" value="Waxing"> Waxing<br><br>
<input type="submit" value="Analyze Selection">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["services"])) {
$services = $_POST["services"];
echo "<div class='results'>";
echo "<h3>1. Selected Services:</h3>";
print_r($services);
echo "<h3>2. Total Services Selected:</h3>";
echo count($services);
// Sort alphabetically
$sortedServices = $services;
sort($sortedServices);
echo "<h3>3. Sorted Alphabetically:</h3>";
print_r($sortedServices);
// Reverse order
$reversedServices = array_reverse($services);
echo "<h3>4. Reversed Order:</h3>";
print_r($reversedServices);
// Remove duplicates (just for demonstration)
$uniqueServices = array_unique($services);
echo "<h3>5. Duplicates Removed:</h3>";
print_r($uniqueServices);
// Search example
$search = "Facial";
echo "<h3>6. Searching for $search:</h3>";
if (in_array($search, $services)) {
echo "$search is in your selection!";
} else {
echo "$search is NOT in your selection.";
}
// Associative array: Service => Length of Name
echo "<h3>7. Associative Array (Service => Length of Name):</h3>";
$serviceLengths = [];
foreach ($services as $service) {
$serviceLengths[$service] = strlen($service);
}
print_r($serviceLengths);
echo "</div>";
} else {
echo "<p>Please select at least one service.</p>";
}
}
// Back link
include('includes/footer.php');
?>