You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
457 B

  1. <?php
  2. /**
  3. * Helper untuk operasi di collection.
  4. *
  5. * @param Array $arr
  6. * @param String $field
  7. *
  8. * @return Array;
  9. */
  10. function colPluck(Array $arr, String $field) {
  11. $result = [];
  12. foreach ($arr as $item) {
  13. array_push($result, $item[$field]);
  14. }
  15. return $result;
  16. }
  17. function colKeyBy(Array $arr, String $key) {
  18. $result = [];
  19. foreach ($arr as $item) {
  20. $result[$item[$key]] = $item;
  21. }
  22. return $result;
  23. }