is_int for values of variables?
Moderator: General Moderators
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
is_int for values of variables?
Basically, all I need is a way to find out whether ($value / 5) is an integer or not. If it is, it'll do one thing, if not it'll do another. I've had a look around the functions at php.net, but haven't had much luck. Whatever the answer is will probably be simple as hell... sometimes it scares me when people say they're newbies and their example code looks a hell of a lot more complicated than what I've been doing... -_-
- cheatboy00
- Forum Contributor
- Posts: 151
- Joined: Sat Jun 29, 2002 10:36 am
- Location: canada
- Contact:
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
then the modulus operator sweahe supposed perfectly fits your needs.
- cheatboy00
- Forum Contributor
- Posts: 151
- Joined: Sat Jun 29, 2002 10:36 am
- Location: canada
- Contact:
then why not something like this
that should work for what you are saying.
Code: Select all
$i = 0;
while (something){
// do stuff
if ($i = 5) {
// do line break
$i = 0;
} else {
$i++;
}
}Just wrap it in a function then:
function is_divisable($value, $divisor = 5) {
if ($value % $divisor) {
// what to do if not an integer
$result = false;
} else {
// Things to do if the result is an integer
$result = true;
}
return $result;
}
and call it from within your while statement.
while( whatever... ) {
if (is_divisable($value)) {
// Add your linebreak
}
}
function is_divisable($value, $divisor = 5) {
if ($value % $divisor) {
// what to do if not an integer
$result = false;
} else {
// Things to do if the result is an integer
$result = true;
}
return $result;
}
and call it from within your while statement.
while( whatever... ) {
if (is_divisable($value)) {
// Add your linebreak
}
}
Last edited by sweahe on Sat Oct 19, 2002 6:58 pm, edited 2 times in total.
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
That'd work too... but the other one's quicker ;pcheatboy00 wrote:then why not something like this
that should work for what you are saying.Code: Select all
$i = 0; while (something){ // do stuff if ($i = 5) { // do line break $i = 0; } else { $i++; } }
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
Code: Select all
if (is_divisable($value, 3)) {
}Code: Select all
if ($value%3 == 0) {
}