What are the best practices for iterating through arrays in PHP to retrieve specific values?

When iterating through arrays in PHP to retrieve specific values, it is best to use a loop such as a foreach loop. This allows you to easily access each element in the array and check for the specific values you are looking for. You can use conditional statements within the loop to filter out the values that meet your criteria.

// Sample array
$fruits = array("apple", "banana", "orange", "kiwi");

// Iterate through the array to retrieve specific values
foreach ($fruits as $fruit) {
    if ($fruit == "banana" || $fruit == "kiwi") {
        echo $fruit . "<br>";
    }
}