What are potential pitfalls of using multiple IF statements to assign values from an array in PHP?

Using multiple IF statements to assign values from an array in PHP can lead to code that is difficult to maintain and understand, especially as the number of conditions grows. A more efficient and cleaner approach is to use a switch statement or a lookup table to map array keys to values.

// Example using a switch statement to assign values from an array
$array = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'];

$key = 'key2';
$value = '';

switch ($key) {
    case 'key1':
        $value = $array['key1'];
        break;
    case 'key2':
        $value = $array['key2'];
        break;
    case 'key3':
        $value = $array['key3'];
        break;
    default:
        $value = 'default value';
}

echo $value; // Output: value2