Instead of writing manual foreach loops to build new arrays, use PHP's functional trio:
array_map()— Transform every item in an arrayarray_filter()— Keep only items that pass a conditionarray_reduce()— Combine all items into a single value (e.g., cart total)
ADVERTISEMENT