What are the best practices for handling dynamic array insertion in PHP when the array size is not predefined?

When dealing with dynamic array insertion in PHP where the array size is not predefined, it is best to use array_push() function to add elements to the end of the array. This allows for flexibility in adding elements without worrying about the initial array size.

// Initialize an empty array
$array = [];

// Add elements dynamically using array_push()
array_push($array, "element1");
array_push($array, "element2");
array_push($array, "element3");

// Print the array
print_r($array);