Created
November 13, 2008 01:21
-
-
Save speedmax/24334 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Min | |
* ======================== | |
* A lightweight framework to provide convient wrappers for PHP to improve | |
* grammers when programming | |
* | |
* @author Taylor luk | |
*/ | |
function a() { | |
return $list = func_get_args(); | |
} | |
function am($key, $value) { | |
return array($key=> $value); | |
} | |
function length($target) { | |
if (is_string($target)) { | |
return strlen($target); | |
} else { | |
return count($target); | |
} | |
} | |
function w($str) { | |
return map(explode(',', $str), 'trim'); | |
} | |
/** | |
* Functional iterators | |
*/ | |
function array_each($array, $callback) { | |
if (!is_callable($callback)) | |
return; | |
foreach($array as $key => $value) { | |
call_user_func($callback, $value, $key); | |
} | |
} | |
function map($list, $callback) { | |
return array_map($callback, $list); | |
} | |
function reduce($list, $initial, $callback) { | |
if (is_callable($initial)) { | |
$callback = $initial; | |
} | |
return array_reduce($list, $callback); | |
} | |
/** | |
* String or pattern operations. | |
*/ | |
function match($pattern, $subject, $matches=array(), $flags=0, $offset=0) { | |
return preg_match($pattern, $subject, $matches, $flags, $offset); | |
} | |
function replace($subject, $search, $replace) { | |
return str_replace($search, $replace, $subject); | |
} | |
function contains($object, $subset) { | |
if (is_string($object)) { | |
return strpos($object, $subset) !== false; | |
} | |
elseif (is_array($object)) { | |
return in_array($object, $setset); | |
} | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment