How can you access specific elements of an array in PHP when using array_diff?

When using array_diff in PHP to compare two arrays and find the difference, you may want to access specific elements that are present in one array but not the other. To do this, you can store the result of array_diff in a variable and then access specific elements by their keys.

$array1 = [1, 2, 3, 4, 5];
$array2 = [3, 4, 5, 6, 7];

$diff = array_diff($array1, $array2);

// Access specific elements by their keys
echo $diff[0]; // Output: 1
echo $diff[1]; // Output: 2