Skip to content

Instantly share code, notes, and snippets.

@jwoodcock
Created February 9, 2015 14:57
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 jwoodcock/887af60afde5ce3ad2d7 to your computer and use it in GitHub Desktop.
Save jwoodcock/887af60afde5ce3ad2d7 to your computer and use it in GitHub Desktop.
Functional PHP Test
<?php
class FunPlay
{
public function getCombinedList($total, $set, $func1, $func2, $count = 0)
{
$return = [];
while ($count < $total) {
array_push(
$return,
$func1(
$set($count),
$func2()
)
);
$count++;
}
return $return;
}
public function printList($list)
{
foreach($list as $item) {
echo $item . '
';
}
}
}
$fun = new FunPlay();
$front = [ 'blue', 'red', 'grey', 'green' ];
$ends = [ 'book', 'chair', 'mouse', 'bottle' ];
$frontItemFunction = function($element) use ($front) {
return $front[$element];
};
$executeFunction= function($first, $second) {
return $first . ' ' . $second;
};
$endItemFunction = function() use ($ends) {
$rand = rand(0, count($ends)-1);
return $ends[$rand];
};
$combinedList = $fun->getCombinedList(
count($front),
$frontItemFunction,
$executeFunction,
$endItemFunction
);
$fun->printList($combinedList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment