Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. <?php
  2. // in PHP arrow functions look like this
  3.  
  4. // long version required currently
  5. function array_values_from_keys($arr, $keys) {
  6. return array_map(
  7. function ($x) use ($arr) { return $arr[$x]; }, // long
  8. $keys
  9. );
  10. };
  11.  
  12. // with arrow functions
  13. function array_values_from_keys($arr, $keys) {
  14. return array_map(
  15. fn($x) => $arr[$x], // short
  16. $keys
  17. );
  18. }
  19.  
  20. // note the difference
  21. $long = function ($x) use ($arr) { return $arr[$x]; };
  22. $short = fn($x) => $arr[$x];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement