-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
39 lines (33 loc) · 1.15 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
function _each($array, $body){
if (!is_callable($body)) throw new Exception("Invalid block.");
foreach($array as $k => $v) call_user_func_array($body, array($k, $v));
}
function _collect($array, $body){
if (!is_callable($body)) throw new Exception("Invalid block.");
$collection = array();
foreach($array as $k => $v) $collection[] = call_user_func_array($body, array($k, $v));
return $collection;
}
function _map($array, $body){
return _collect($array, $body);
}
function _select($array, $body){
if (!is_callable($body)) throw new Exception("Invalid block.");
$collection = array();
foreach($array as $k => $v) if (call_user_func_array($body, array($k, $v))) $collection[] = $v;
return $collection;
}
function _at($array, $at){
if (!is_numeric($at)) throw new Exception("Invalid index.");
if ($at >= 0) return $array[$at];
return $array[sizeof($array) + $at];
}
function _compact($array){
$collection = array();
foreach($array as $k => $v) if ($v != null) $collection[] = $v;
return $collection;
}
?>