In what situations would it be more efficient to use functional programming techniques, like foreach loops, compared to implementing OOP principles in PHP code?

Functional programming techniques like foreach loops are more efficient when dealing with simple data transformations or operations that don't require complex object-oriented structures. In cases where you need to iterate over arrays or collections of data and perform a specific action on each element, using functional programming can lead to cleaner and more concise code compared to creating classes and objects.

// Using a foreach loop to capitalize each element in an array
$data = ['apple', 'banana', 'cherry'];

foreach($data as $key => $value) {
    $data[$key] = strtoupper($value);
}

print_r($data);