Q
PHP的功能风格
3
A
回答
3
根据PHP文档,PHP 4.0.1和PHP 5有以下方法来创建拉姆达式功能:
0
以防万一,人们仍有兴趣这样的库,请查看Saber功能PHP库。
1
Non-stardard PHP library (NSPL)使得使用PHP编写功能代码更容易。看看与NSPL写下面的代码:
// get user ids
$userIds = map(propertyGetter('id'), $users);
// or sort them by age
$sortedByAge = sorted($users, methodCaller('getAge'));
// or check if they all are online
$online = all($users, methodCaller('isOnline'));
// or define new function as composition of the existing ones
$flatMap = compose(rpartial(flatten, 1), map);
在纯PHP就应该是这样的:
// get user ids
$userIds = array_map(function($user) { return $user->id; }, $users);
// sort them by age, note that the following code modifies the original users array
usort($users, function($user1, $user2) {
return $user1->getAge() - $user2->getAge();
});
// check if they all are online
$online = true;
foreach ($users as $user) {
if (!$user->isOnline()) {
$online = false;
break;
}
}
// define new function as composition of the existing ones
$flatMap = function($function, $list) {
// note the inconsistency in array_map and array_reduce parameters
return array_reduce(array_map($function, $list), 'array_merge', []);
};
相关问题
- 1. PHP风格功能检查在javascript
- 2. JSF 2 Scriptmanager风格功能
- 3. WPF中的Mac风格DockBar功能
- 4. Office 2010风格的MFC功能包
- 5. Openlayers风格的CSS功能弹出
- 6. 功能风格的对象模型?
- 7. 原型功能的编码风格
- 8. 风格的jQuery功能设置回传
- 9. 功能风格的重写循环
- 10. XAML到C#的功能,通用的风格或功能
- 11. 网络展望风格功能区
- 12. 实现Facebook风格“不像”功能
- 13. PHP风格
- 14. 手风琴功能
- 15. PHP风格问题
- 16. PHP,GD和风格
- 17. PHP的echo VS JSP风格
- 18. REST风格的URL和PHP
- 19. 不能在风格
- 20. 更换while循环用惯用的功能的风格
- 21. 的OpenLayers 3将活力四射的风格与解析功能
- 22. 创建过于简单的功能是不好的风格吗?
- 23. RubyMine是否具有TextMate风格的多行编辑功能?
- 24. 如何做功能风格的文件创建和操作?
- 25. 如何实现Windows的Mac风格Windowshade功能
- 26. Matlab中的Bash风格编程引用功能?
- 27. VS:工具提示帮助doxygen风格的评论功能?
- 28. CSS和Javascript:改变颜色效果悬停风格的功能
- 29. 调试F#代码和功能的风格
- 30. 如何写yii2的contentOptions有功能和风格?
究竟做ü希望能够做什么? – Neal 2011-03-31 18:47:36
你需要更具体。你在寻找什么功能?没有支持类lambda表达式的库,因为这是解析器本身内部的语法语言功能。 – Unsigned 2011-03-31 18:49:29