Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions data/04-arrays/examples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$prices = [10, 20, 30, 40, 50];

// Use array_filter to get prices above 25
$expensive = array_filter($prices, function($price) {
return $price > 25;
});

// Use array_map to add 10% tax to each price
$withTax = array_map(fn($p) => $p * 1.10, $prices);

print_r($expensive);
print_r($withTax);

?>
8 changes: 8 additions & 0 deletions data/04-arrays/guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Modern PHP Array Manipulation

PHP 8.x offers several powerful functions to handle arrays without using messy `foreach` loops for every operation.

### Key Takeaways
* **`array_map`**: Applies a callback to every element in the array.
* **`array_filter`**: Filters elements based on a specific boolean condition.
* **Cleaner Code**: Using these functions makes your backend logic more functional and less prone to "off-by-one" errors.
Loading