PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dimxasnewfrozen
Forum Commoner
Posts: 84 Joined: Fri Oct 30, 2009 1:21 pm
Post
by dimxasnewfrozen » Fri Apr 23, 2010 10:57 am
I have the following code:
Code: Select all
$mins = 75;
$mins = $mins / 60; // returns 1.25
list($hrs, $mins) = split(".", $mins, 2); //I want to return 1 and .25 separately
$mins = $mins * .60; // should return 15
I need a way to split the decimal so that I can get the two parts but I'm not returning the first part (which in this case is a 1).
dimxasnewfrozen
Forum Commoner
Posts: 84 Joined: Fri Oct 30, 2009 1:21 pm
Post
by dimxasnewfrozen » Fri Apr 23, 2010 11:01 am
Well... this always seem to happen... as soon as I submit the post, I found a solution:
Code: Select all
$mins = $minutes / 60;
$time = explode(".", $mins);
echo $time[0];
echo $time[1];
phu
Forum Commoner
Posts: 61 Joined: Tue Mar 30, 2010 6:18 pm
Post
by phu » Fri Apr 23, 2010 11:59 am
You could also use...
Unlike explode(), it will give you a numeric type. Not all that necessary with PHP, but still good practice.