How can PHP developers efficiently assign array values to a new variable before displaying them?

When working with arrays in PHP, developers may need to assign array values to a new variable before displaying them. This can be done efficiently using the array_values() function, which returns all the values of an array as a new indexed array. By assigning the result of array_values() to a new variable, developers can easily access and display the array values without worrying about the original keys.

// Original array
$array = ['apple' => 'red', 'banana' => 'yellow', 'grape' => 'purple'];

// Assign array values to a new variable
$newArray = array_values($array);

// Display the values of the new array
foreach ($newArray as $value) {
    echo $value . "<br>";
}