How can the code snippet provided be optimized to avoid unnecessary iterations through the array?
The issue with the current code snippet is that it uses two nested loops to iterate through the array, which can be inefficient for large arrays. To optimize this, we can use the PHP in_array() function to check if a specific value exists in the array without the need for nested loops.
// Optimized code snippet to avoid unnecessary iterations through the array
$target = 42;
$numbers = [10, 20, 30, 40, 50];
if (in_array($target, $numbers)) {
echo "The target number $target is present in the array.";
} else {
echo "The target number $target is not present in the array.";
}