Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Смысл LINQ именно в синтаксисе
echo Phinq::create($people)
->groupBy(function($person) { return $person->residence->region; })
->select(function($grouping) {
$obj = new stdClass();
$obj->people = $grouping;
$obj->region = $grouping->getKey();
return $obj;
})->orderBy(function($obj) { return $obj->people->count(); }, true)
->aggregate(function($current, $next) {
$count = $next->people->count();
return $current . sprintf(
"%d %s (%s) live in the %s region\n",
$count,
$count === 1 ? 'person' : 'people',
$next->people->aggregate(function($current, $next) {
if ($current !== null) {
$current .= ', ';
}
return $current . sprintf('%s [%s]', $next->name, $next->residence->code);
}),
$next->region
);
});
Язык LINQ мне кажется очень выразительным.
from($categories)
->orderBy('$v["name"]')
->groupJoin(
from($products)
->where('$v["quantity"] > 0')
->orderByDescending('$v["quantity"]')
->thenBy('$v["name"]'),
'$v["id"]', '$v["catId"]', 'array("name" => $v["name"], "products" => $e)'
);
from($categories)
->orderBy('$v["name"]')
->groupJoin(
from($products)
->where('$v["quantity"] > 0')
->orderByDescending('$v["quantity"]')
->thenBy('$v["name"]'),
'$v["id"]', '$v["catId"]', 'array("name" => $v["name"], "products" => $e)'
);
$array = array();
for ($elements as $element) {
if ($element['foo'] == 'bar') {
$array[] = $element['baz'];
}
}
return $array;
return from($elements)->where('$v["foo"] == "bar"')->select('$v["baz"]')->toArray();
LINQ для PHP. Часть 1. Я его слепила из того, что было, а потом, что было, то и полюбила