PHPLinq 배열 예제

Jmnote (토론 | 기여)님의 2014년 8월 31일 (일) 16:07 판 (새 문서: ;PHPLinq 예제 ==소스 코드== <source lang='PHP'> <?php error_reporting(E_ALL); set_include_path(get_include_path().PATH_SEPARATOR.'/var/www/php_lib/PHPLinq/'); require_once 'PHP...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
PHPLinq 예제

소스 코드

<?php
error_reporting(E_ALL);
set_include_path(get_include_path().PATH_SEPARATOR.'/var/www/php_lib/PHPLinq/');
require_once 'PHPLinq/LinqToObjects.php';
function xmp($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }

// 데이터 입력
$names = array("John", "Peter", "Joe", "Patrick");

// 데이터 조작, 출력
$result = from('$name')->in($names)
	->where('$name => strlen($name) < 5')
	->select('$name');
xmp($result);
// Array
// (
//     [0] => John
//     [1] => Joe
// )

$result = from('$name')->in($names)->reverse()->select();
xmp($result);
// Array
// (
//     [0] => Patrick
//     [1] => Joe
//     [2] => Peter
//     [3] => John
// )

xmp( 'count: ' . from('$name')->in($names)->count() );
// count: 4

xmp( 'elementAt(2): ' . from('$name')->in($names)->elementAt(2) );
// elementAt(2): Joe

$result = from('$name')->in($names)->concat(array("Maarten"))->select('$name');
xmp( $result );
// Array
// (
//     [0] => John
//     [1] => Peter
//     [2] => Joe
//     [3] => Patrick
//     [4] => Maarten
// )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}