What are the advantages and disadvantages of using integer index values versus string values for user input in PHP?
When taking user input in PHP, using integer index values can offer faster and more efficient data retrieval compared to string values. However, using string values can make the code more readable and user-friendly. It is important to consider the trade-offs between performance and usability when deciding whether to use integer index values or string values for user input.
// Using integer index values for user input
$userInput = $_GET['input'];
$allowedValues = ['apple', 'banana', 'orange'];
if (isset($allowedValues[$userInput])) {
$selectedFruit = $allowedValues[$userInput];
echo "You selected: " . $selectedFruit;
} else {
echo "Invalid input";
}