for KIA
Tuesday, March 23, 2004
Description: int() - a custom php function
<?
function int($number) {
// usage: int(N)
// where N = a floating point number, e.g. 3.14
$int = explode(".",$number);
return $int[0];
}
?>
Tuesday, March 23, 2004 08:38am PST
Just so you know:
$number is the number that the function takes in, it does not have to be:
int($number)
it can be:
int(3.14)
or:
int($mycrazyvariablethatholdsthenumber)
etc
This basically takes a floating point number and breaks it into pieces according to the decimal point and returns the first part of it (the integer). It's just a faster way to do it if you're going to use it a lot, instead of just doing explode everytime.
The explode function is breaking the variable's content's into pieces according to the decimal point and returning an array. You notice that I return $int[0] because that's the first item in the array (it starts with 0), which holds the integer part of our number :)
Tuesday, March 23, 2004 09:01am PST
using int(), I added a duration() which I hope to change up a bit later.
Right now the syntax is:
duration(number)
and I soon hope to make it:
duration(number,fmt) where fmt is an int (1-3)
this is the first thing i've *ever* done in PHP (please don't laugh at me =( )and bh is making me post it so i guess i'll post it...
function duration($number) {
$mysecs = $number;
$myweeks = int($mysecs / 604800);
$mysecs = $mysecs - $myweeks * 604800;
$mydays = int($mysecs / 86400);
$mysecs = $mysecs - ($mydays * 86400);
$myhours = int($mysecs / 3600);
$mysecs = $mysecs - ($myhours * 3600);
$mymins = int($mysecs / 60);
$mysecs = $mysecs - ($mymins * 60);
if ($myweeks == 1) $myweeks2 = "$myweeks week";
elseif ($myweeks != 0) $myweeks2 = "$myweeks weeks";
if ($mydays == 1) $mydays2 = "$mydays day";
elseif ($mydays != 0) $mydays2 = "$mydays days";
if ($myhours == 1) $myhours2 = "$myhours hour";
elseif ($myhours != 0) $myhours2 = "$myhours hours";
if ($mymins == 1) $mymins2 = "$mymins minute";
elseif ($mymins != 0) $mymins2 = "$mymins minutes";
if ($mysecs == 1) $mysecs2 = "$mysecs second";
elseif ($mysecs != 0) $mysecs2 = "$mysecs seconds";
$mytime = "$myweeks2 $mydays2 $myhours2 $mymins2 $mysecs seconds";
return $mytime;
}
Monday, March 29, 2004 09:45am PST
lol KIA.... lol
Submit a comment
Oops! You need to
login or
register before you can post a comment!