Created
February 9, 2015 14:57
-
-
Save jwoodcock/887af60afde5ce3ad2d7 to your computer and use it in GitHub Desktop.
Functional PHP Test
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 | |
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