How can one write to an associative array in PHP?

To write to an associative array in PHP, you can simply assign a value to a specific key within the array. This can be done by using square brackets with the key inside them on the left side of the assignment operator. This will either create a new key-value pair if the key doesn't already exist, or update the existing value if the key is already present.

// Create an empty associative array
$myArray = [];

// Write to the associative array by assigning a value to a specific key
$myArray['key1'] = 'value1';
$myArray['key2'] = 'value2';

// Print the associative array to see the changes
print_r($myArray);