PHPLinq 2차원 배열 employees 예제

1 사전 작업[ | ]

2 employees.php 작성[ | ]

[root@zetawiki ~]# vi employees.php
<?php
set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php/vendor/phplinq/');
include 'PHPLinq/LinqToObjects.php';

$employees = array(
	(object) array('EmployeeID'=>'1', 'Name'=>'한놈', 'BirthDate'=>'2000-01-01'),
	(object) array('EmployeeID'=>'2', 'Name'=>'두시기', 'BirthDate'=>'1990-01-01'),
	(object) array('EmployeeID'=>'3', 'Name'=>'석삼', 'BirthDate'=>'1980-01-01'),
	(object) array('EmployeeID'=>'4', 'Name'=>'너구리', 'BirthDate'=>'2000-01-01')
);

$result = from('$employee')->in($employees)
	->where('$employee => $employee->BirthDate > "1985-01-01"')
	->orderByDescending('$employee => $employee->BirthDate')
	->thenBy('$employee => $employee->Name')
	->select('$employee');
print_r($result);
→ 생년월일(BirthDate)이 1985-01-01 이후인 직원 중에서...
→ 생년월일 역순 정렬, 생년월일이 같다면 이름순 정렬

3 실행 결과[ | ]

[root@zetawiki ~]# php employees.php
Array
(
    [0] => stdClass Object
        (
            [EmployeeID] => 4
            [Name] => 너구리
            [BirthDate] => 2000-01-01
        )

    [1] => stdClass Object
        (
            [EmployeeID] => 1
            [Name] => 한놈
            [BirthDate] => 2000-01-01
        )

    [2] => stdClass Object
        (
            [EmployeeID] => 2
            [Name] => 두시기
            [BirthDate] => 1990-01-01
        )

)

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}