PHP の配列操作

2022/05/15

arra_values()

array_filter()

function getEmployeeList(string $dept_name): array
{
    return array_values(
        array_filter(
            $employees,
            function($employee) use ($dept_name) {
                return $employee->getDeptName() === $dept_name;
            }
        )
    );
}

例えばこんな感じ。

「ある部署に所属する社員全員の一覧」を社員データの配列 $employees (各要素はドメインリポジトリで定義された Employee オブジェクト) から部署名 $dept_name で抽出するケース。

その他

Eloquent の orderBy()


Written by Circle
A mound built by the accumulation of hyperlinks are like Kowloon.