Last active
December 17, 2015 01:59
-
-
Save wizardfrag/5532597 to your computer and use it in GitHub Desktop.
Convert a time string to an integer.
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 string2int($string = "00:00:00") { | |
$seconds = 0; | |
$string_parts = explode(':', $string); | |
$exponent = 0; | |
while (($timepart = array_pop($string_parts)) !== NULL) { | |
$timepart = intval($timepart); | |
$seconds += intval($timepart * pow(60, $exponent)); | |
$exponent++; | |
} | |
return $seconds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment