What is the best approach to dynamically create associative arrays in PHP?

When dynamically creating associative arrays in PHP, the best approach is to use the square bracket syntax to define keys and values within the array. This allows for flexibility in adding new key-value pairs without having to predefine the array structure.

// Dynamically create an associative array
$array = [];

// Add key-value pairs dynamically
$array['key1'] = 'value1';
$array['key2'] = 'value2';
$array['key3'] = 'value3';

// Print the array
print_r($array);