Last active
November 30, 2016 04:03
-
-
Save anggadarkprince/e8e4baf15ee9c2507f20c5b28c3f28a4 to your computer and use it in GitHub Desktop.
Dynamic Function
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 | |
$words = ['dibawakan', "dimakan", "menangis"]; | |
$list = ['bawa', 'makan']; | |
$complete = []; | |
$functions = ['trim_prefix', 'trim_suffix', 'trim_another_affix']; | |
function trim_prefix($word){ | |
if(preg_match('/^(di|[ks]e)/', $word)){ | |
return preg_replace('/^(di|[ks]e)/', '', $word); | |
} | |
return $word; | |
} | |
function trim_suffix($word){ | |
if(preg_match('/(kan)$/', $word)){ | |
return preg_replace('/(kan)$/', '', $word); | |
} | |
return $word; | |
} | |
function trim_another_affix($word){ | |
return $word; | |
} | |
foreach ($words as $word) { | |
foreach ($functions as $callable) { | |
$word = call_user_func($callable, $word); | |
if(in_array($word, $list)){ | |
array_push($complete, $word); | |
break; | |
} | |
} | |
} | |
print_r($complete); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment