underscore.php

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

underscore是前端常用的javascript庫,最近無意中發現原來它還有PHP的移植

基本介紹

絕大部分函式都移植過來了。underscore.js用的是_

或者,如果你偏愛靜態風格:

__::map(array(1, 2, 3), function($n) { return $n * 3; });

結果:

Array
(
[0] => 3
[1] => 6
[2] => 9
)

安裝

composer

一般用Composer安裝:

"anahkiasen/underscore-php" : "dev-master"

Laravel

如果用Laravel框架,可以用artisan

然後在bundles檔案中加入這行:

'underscore' => array('auto' => true),

include/require

如果你這麼傳統……那當然也是可以的。

函式一覽

絕大部分都移植過來了:

Collections

each, map, reduce, reduceRight, detect, select, reject, all, any, includ, invoke, pluck, max, min, groupBy, sortBy, sortedIndex, toArray, size

Arrays

first, rest, last, compact, flatten, without, uniq, union, intersection, difference, zip, indexOf, lastIndexOf, range

Functions

memoize, throttle, once, after, wrap, compose

Objects

keys, values, functions, extend, defaults, clon, tap, isEqual, isEmpty, isObject, isArray, isFunction, isString, isNumber, isBoolean, isDate, isNaN, isNull

Utility

identity, times, mixin, uniqueId, template

Chaining

chain, value

我自己更習慣寫原生PHP。不過這個庫可以幫助從前端轉過來的同學,所以這裡和大家分享一下。

相關文章

程式語言 最新文章