How can PHP arrays be manipulated to store multiple values for a single key?
To store multiple values for a single key in a PHP array, you can use nested arrays or associative arrays. This allows you to group related values together under the same key. You can then access these values by referencing the key and the specific index of the nested array.
// Using nested arrays to store multiple values for a single key
$multiValues = [
'key1' => ['value1', 'value2'],
'key2' => ['value3', 'value4'],
];
// Accessing values for 'key1'
echo $multiValues['key1'][0]; // Output: value1
echo $multiValues['key1'][1]; // Output: value2