LoginSignup
11
11

More than 5 years have passed since last update.

CakePHPでCollection使ってますか?

Last updated at Posted at 2015-09-16

CakePHPでCollection使ってますか?

CollectionはCakePHP公式のGinqのような配列操作の為のライブラリです。

CakePHP3にはデフォルトで組み込まれているのですが、CakePHP3に依存しない形で実装されていますので、CakePHP2にも導入が可能 です。

詳細は以下のマニュアルやリポジトリを見てください。

http://book.cakephp.org/3.0/en/core-libraries/collections.html

https://github.com/cakephp/collection

とりあえずインストールしたい!

"require" : {
    "cakephp/collection": "~3.0"
}

とりあえず動かしたい!

他にも機能はたくさんあります。

便利ー

$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);

// 値が1より大きいものを取り出す
$overOne = $collection->filter(function ($value, $key, $iterator) {
    return $value > 1;
});
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11