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

(새 문서: ==사전 작업== *PHPLinq 2차원 배열 employees 예제 ==employees2.php== <source lang='cli'> [root@zetawiki ~]# vi employees2.php </source> <source lang='php'> <?php set_inc...)
 
2번째 줄: 2번째 줄:
*[[PHPLinq 2차원 배열 employees 예제]]
*[[PHPLinq 2차원 배열 employees 예제]]


==employees2.php==
==employees2.php 작성==
<source lang='cli'>
<source lang='cli'>
[root@zetawiki ~]# vi employees2.php
[root@zetawiki ~]# vi employees2.php

2015년 6월 23일 (화) 17:05 판

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 }}