How can the PHP function array_slice be used to extract specific elements from an array?

To extract specific elements from an array in PHP, you can use the array_slice function. This function allows you to specify the starting index and the length of the slice you want to extract from the array. By providing the array, the starting index, and the length, you can retrieve the desired elements from the array.

// Example of using array_slice to extract specific elements from an array
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$slice = array_slice($array, 2, 3); // Extract elements starting from index 2 with a length of 3
print_r($slice); // Output: Array ( [0] => 3 [1] => 4 [2] => 5 )