Underscore.php 시작하기

Underscore.php 시작하기
Underscore.php 튜토리얼
Underscore.php 설치

1 git으로 설치[ | ]

[root@zetawiki ~]# mkdir -p /usr/share/php/vendor/
[root@zetawiki ~]# cd /usr/share/php/vendor/
[root@zetawiki vendor]# git clone https://github.com/brianhaveri/Underscore.php.git
Initialized empty Git repository in /root/Underscore.php/.git/
remote: Counting objects: 1254, done.
remote: Total 1254 (delta 0), reused 0 (delta 0), pack-reused 1254
Receiving objects: 100% (1254/1254), 308.31 KiB | 217 KiB/s, done.
Resolving deltas: 100% (591/591), done.

2 예제 생성[ | ]

[root@zetawiki vendor]# cd
[root@zetawiki ~]# vi underscore1.php
<?php
include '/usr/share/php/vendor/Underscore.php/underscore.php';

$arr = array(51,42,33,24,15);

// each 예제 ( 각각 출력 )
__::each($arr, function($num) {
	var_dump( $num );
});

// filter 예제 (짝수만 필터링. 42, 24)
$even_numbers = __::filter($arr, function($num) { return $num%2 == 0; });
print_r( $even_numbers );

// 차집합 구하기
$arr1 = array('A', 'B', 'C', 'D');
$arr2 = array('C', 'D', 'E', 'F');
print_r( __::difference($arr1, $arr2) );

3 테스트[ | ]

[root@zetawiki ~]# php underscore1.php 
int(51)
int(42)
int(33)
int(24)
int(15)
Array
(
    [0] => 42
    [1] => 24
)
Array
(
    [0] => A
    [1] => B
)

4 같이 보기[ | ]

5 참고[ | ]

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