How can keys and values be added to an array in PHP simultaneously?

To add keys and values to an array simultaneously in PHP, you can use the array_combine function. This function takes two arrays as arguments, one for keys and one for values, and creates a new array where the elements in the first array are used as keys and the elements in the second array are used as values.

// Define key array
$keys = array('key1', 'key2', 'key3');

// Define value array
$values = array('value1', 'value2', 'value3');

// Combine keys and values into a new array
$array = array_combine($keys, $values);

// Output the resulting array
print_r($array);