Skip to content

Instantly share code, notes, and snippets.

@koduki
Created June 9, 2009 23:36
Show Gist options
  • Save koduki/126899 to your computer and use it in GitHub Desktop.
Save koduki/126899 to your computer and use it in GitHub Desktop.
<?php
function p($xs){
foreach($xs as $x) print("$x ");
print "\n";
}
function split2($xs){
if(count($xs) == 1) return array($xs, array());
list($l, $r) = array_chunk($xs, 2);
return array();
}
function msort($xs){
list($l, $r) = split($xs);
return merge(
(count($xs) <= 2) ? array(l, r)
: array(msort(l), msort(r)));
}
$xs = range(0, 20);
shuffle($xs);
p($xs);
list($x, $y) = array(array(1,2,3), array(6));
print_r(array_chunk(array(1,2), 2));
print_r(array_chunk(array(1), 2));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment