Are there built-in PHP functions that can automatically fill empty spaces in an array?

When working with arrays in PHP, there is no built-in function that automatically fills empty spaces in an array. However, you can achieve this by iterating through the array and checking for empty values, then filling them with a specified default value.

<?php
// Sample array with empty spaces
$array = [1, 2, null, 4, '', 6];

// Fill empty spaces with a default value
foreach ($array as $key => $value) {
    if (empty($value)) {
        $array[$key] = 'default';
    }
}

// Output the modified array
print_r($array);
?>