How can variables be concatenated in PHP to access elements in multiple arrays?

To concatenate variables in PHP to access elements in multiple arrays, you can use the concatenation operator (.) to combine the variable names. This allows you to dynamically access elements in arrays based on the concatenated variable names.

$array1 = ['a' => 1, 'b' => 2];
$array2 = ['c' => 3, 'd' => 4];

$key1 = 'a';
$key2 = 'c';

$result = $array1[$key1] . $array2[$key2]; // Accesses $array1['a'] and $array2['c']

echo $result; // Outputs 13