Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // in PHP arrow functions look like this
- // long version required currently
- function array_values_from_keys($arr, $keys) {
- return array_map(
- function ($x) use ($arr) { return $arr[$x]; }, // long
- $keys
- );
- };
- // with arrow functions
- function array_values_from_keys($arr, $keys) {
- return array_map(
- fn($x) => $arr[$x], // short
- $keys
- );
- }
- // note the difference
- $long = function ($x) use ($arr) { return $arr[$x]; };
- $short = fn($x) => $arr[$x];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement