Last active
August 29, 2015 14:24
-
-
Save r3wt/f12e1b65788f16ae5703 to your computer and use it in GitHub Desktop.
create a contiguous subarray lambda
This file contains hidden or 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
<?php | |
function create_csl($length = 3,$comparison_operator = '>') | |
{ | |
$fn = ''; | |
$i = 0; | |
while(true) | |
{ | |
if($i == 0) | |
{ | |
$fn.='return ( (bool) '; | |
} | |
$fn .= '$a['.$i.'] '.$comparison_operator.' $a['. ($i+1) .']'; | |
if($length > 1) | |
{ | |
$fn.= ' && '; | |
} | |
if($length == 1) | |
{ | |
$fn.=' );'; | |
break; | |
} | |
$length--; | |
$i++; | |
} | |
return create_function('$a',$fn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment