Skip to content

Instantly share code, notes, and snippets.

@marcmascort
Created September 6, 2014 00:33
Show Gist options
  • Save marcmascort/c7b002fe46ae10e215a9 to your computer and use it in GitHub Desktop.
Save marcmascort/c7b002fe46ae10e215a9 to your computer and use it in GitHub Desktop.
Divide array by golden ratio
<?php
function divide_array_by_golden_ratio($arr)
{
$ab = count($arr);
if ($ab < 2)
{
return false;
}
$phi = (1 + sqrt(5)) / 2;
$a = round($ab / $phi);
$b = $ab - $a;
$arr_a = array_slice($arr, 0, $a);
$arr_b = array_slice($arr, $a, $b);
return array($arr_a, $arr_b);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment