简介:这是php闭包实验的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=336629' scrolling='no'>class IArray extends ArrayObject { static function make($array) { return new self($array); } function map($func) { $res = new self(); foreach ($this as $k => $v) { $res[$k] = $func($k, $v); } return $res; } function filter($func) { $res = new self(); foreach ($this as $k => $v) { if ($func($k, $v)) { $res[$k] = $v; } } return $res; } } $nums = array(10,20,30,40); $res = IArray::make($nums)->filter(function($k, $v) { return $v > 15; })->map(function($k, $v) { return $v * 2; }); print_r($res);