Created
December 31, 2015 10:36
-
-
Save zawmyohtet/1bed2749b6d03410f302 to your computer and use it in GitHub Desktop.
My CodeFight HappyNewYear Challenge solution
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 | |
function happyNewYear($wish){ | |
$st = explode(" ", addslashes($wish)); | |
$mx = max(array_map("strlen", $st)); | |
$re[] = str_repeat("*", $mx + 4); | |
for ($i = 0; $i < sizeof($st); $i++ ){ | |
$re[] = "* " . $st[$i] . str_repeat(" ", ($mx - strlen($st[$i]))) . " *" ; | |
} | |
$re[] = $re[0]; | |
return $re; | |
} | |
print_r(happyNewYear("Happy's New Year and CodeFight On in 2016!")); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment