"PHPLinq 2차원 배열 employees 예제 2"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
3번째 줄: 3번째 줄:


==employees2.php 작성==
==employees2.php 작성==
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# vi employees2.php
[root@zetawiki ~]# vi employees2.php
</source>
</source>
29번째 줄: 29번째 줄:


==실행 결과==
==실행 결과==
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# php employees2.php
[root@zetawiki ~]# php employees2.php
Array
Array

2016년 3월 29일 (화) 11:00 판

1 사전 작업

2 employees2.php 작성

[root@zetawiki ~]# vi employees2.php
<?php
set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php/vendor/phplinq/');
include 'PHPLinq/LinqToObjects.php';
function arrs2objs(&$a) { foreach($a as $k=>$v)$a[$k]=(object)$v; }

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

$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);

3 실행 결과

[root@zetawiki ~]# php employees2.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 }}