What is the best way to extract values from an array in PHP?

When extracting values from an array in PHP, the best way is to use array functions such as array_shift, array_pop, array_slice, or array_values. These functions allow you to extract values from the beginning, end, or specific positions within the array without modifying the original array. Additionally, you can use foreach loops or array indexing to iterate through the array and extract values as needed.

// Example of using array_shift to extract the first value from an array
$array = [1, 2, 3, 4, 5];
$firstValue = array_shift($array);
echo $firstValue; // Output: 1

// Example of using array_pop to extract the last value from an array
$array = [1, 2, 3, 4, 5];
$lastValue = array_pop($array);
echo $lastValue; // Output: 5

// Example of using array_slice to extract values from a specific position in an array
$array = [1, 2, 3, 4, 5];
$values = array_slice($array, 1, 3);
print_r($values); // Output: Array ( [0] => 2 [1] => 3 [2] => 4 )