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

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


==employees2.php 작성==
==employees2.php 작성==
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# vi employees2.php
[root@zetawiki ~]# vi employees2.php
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php/vendor/phplinq/');
set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php/vendor/phplinq/');
26번째 줄: 26번째 줄:
->select('$employee');
->select('$employee');
print_r($result);
print_r($result);
</source>
</syntaxhighlight>


==실행 결과==
==실행 결과==
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# php employees2.php
[root@zetawiki ~]# php employees2.php
Array
Array
55번째 줄: 55번째 줄:


)
)
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:56 기준 최신판

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