Skip to content

Instantly share code, notes, and snippets.

@cobodo
Created November 12, 2013 12:57
Show Gist options
  • Save cobodo/7430372 to your computer and use it in GitHub Desktop.
Save cobodo/7430372 to your computer and use it in GitHub Desktop.
現実逃避
<?php
function array_reduce_kv ($arr, $callable, $init = null) {
if (!is_callable($callable)) {
return $init;
}
foreach ($arr as $k=>$v) {
$init = $callable($init, $v, $k);
}
return $init;
}
function array_map_kv ($arr, $callable) {
if (!is_callable($callable)) {
return $arr;
}
$ret = array();
foreach ($arr as $k=>$v) {
$ret[$k] = $callable($v,$k);
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment