What are the potential pitfalls of using array_push() with associative arrays in PHP?

When using array_push() with associative arrays in PHP, the function will always append values to the end of the array, regardless of the keys. This can lead to unexpected behavior if you are relying on specific key-value pair ordering. To avoid this issue, you can use direct assignment to add elements to an associative array, specifying the key explicitly.

// Using direct assignment to add elements to an associative array
$assocArray = array(
    'key1' => 'value1',
    'key2' => 'value2'
);

$assocArray['key3'] = 'value3';
$assocArray['key4'] = 'value4';

print_r($assocArray);