What are some alternative solutions to using switch-case or if statements when displaying multiple text fields in PHP?

Using a key-value array to map the text fields can be a more efficient and cleaner solution compared to using switch-case or if statements. By storing the text fields in an associative array, you can easily retrieve and display the desired text field based on a given key.

$textFields = [
    'field1' => 'Text for field 1',
    'field2' => 'Text for field 2',
    'field3' => 'Text for field 3',
];

$fieldKey = 'field2';

echo $textFields[$fieldKey];