-
-
Save jingmian/0f5f07161783a88c9fbfaf54a731434f to your computer and use it in GitHub Desktop.
问题整理
This file contains 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
## $item->{$func} | |
如果是类,不应该是$item->{$func}()? | |
function groupBy($items, $func) | |
{ | |
$group = []; | |
foreach ($items as $item) { | |
if ((!is_string($func) && is_callable($func)) || function_exists($func)) { | |
$key = call_user_func($func, $item); | |
$group[$key][] = $item; | |
} elseif (is_object($item)) { | |
$group[$item->{$func}][] = $item; | |
} elseif (isset($item[$func])) { | |
$group[$item[$func]][] = $item; | |
} | |
} | |
return $group; | |
} | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment