Skip to content

Instantly share code, notes, and snippets.

@r3wt
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r3wt/f12e1b65788f16ae5703 to your computer and use it in GitHub Desktop.
Save r3wt/f12e1b65788f16ae5703 to your computer and use it in GitHub Desktop.
create a contiguous subarray lambda
<?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