[php] php lambda

WBOY
Release: 2016-06-23 14:29:20
Original
2956 people have browsed it

1 <?php2 // http://cn.php.net/manual/zh/function.create-function.php3 $lambda = create_function('$a,$b','return ($a > $b)? $a : $b;');4 var_dump($lambda);5 echo $lambda(1,2);
Copy after login

下面一些具体的示例

 1 function do_foreach($arrData,$func) { 2     $arrResult = array();  3     foreach($arrData as $row) { 4         if($return = $func($row)) { 5             $arrResult[] = $return; 6         } 7     } 8     return $arrResult; 9 }10 11 // 所有元素+112 $func1 = 'return $row + 1;';13 var_dump(do_foreach(array(1,2,3,4),create_function('$row',$func1)));14 15 // 所有元素平方16 $func1 = 'return $row * $row;';17 var_dump(do_foreach(array(1,2,3,4),create_function('$row',$func1)));18 19 // 只是输出20 $func1 = 'echo $row,"<br/>";';21 do_foreach(array(1,2,3,4),create_function('$row',$func1));
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!