Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Last active January 12, 2016 09:24
Show Gist options
  • Save khoand0000/761d1a07391dfb5f13de to your computer and use it in GitHub Desktop.
Save khoand0000/761d1a07391dfb5f13de to your computer and use it in GitHub Desktop.
Code style when using underscore in php
  • I am using the php underscore
  • Use closures and assign them to variables
  • Put variables at begin of the function, main code will after ////////
  • Must be
function sumPrice($items) {
  $sum = function ($memo, $item) {
    return $memo + $item['price'];
  }
  
  /////////
  
  return Underscore::from($items)->reduce($sum, 0)->value();
}
  • Don't
function sumPrice($items) {
  return Underscore::from($items)->reduce(function ($memo, $item) {
    return $memo + $item['price'];
  }, 0)->value();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment