-
-
Save tarnfeld/2889300 to your computer and use it in GitHub Desktop.
Simple PHP Quiz
This file contains 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 | |
$string = "January 5th, 2012"; | |
list($month, $day, $year) = array_map(function($v) { return trim($v, ","); }, explode(" ", $string)); | |
var_dump($month, $day, $year); | |
// string(7) "January" | |
// string(3) "5th" | |
// string(4) "2012" |
This file contains 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
// Fun little quiz | |
Assuming this string: "January 5th, 2012" | |
In the shortest amount of code possible, place: | |
- 'January' within a $month variable | |
- '5th' within a $day variable | |
- '2012' within a $year variable. | |
See if you can accomplish this with one line of code. (And no snarky $month = 'January' answers. | |
Assume that the format always stays the same, but month, day, and year values can change with each referesh. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment