I have an array, I want to check for errors before placing in my db.
Now, these values can only have possible values of x.25, x.50, x.75 , x.00 or x. so I want to do a foreach loop through the array and determine if any of these values doesn't meet that criteria.
I've tried several different approaches including:
Which didn't work, well I don't know why, maybe because the values are strings? also the modulus (%) doesn't seem to work with decimals.
I also tried:
Which didn't work either, I think because a division operator automatically makes it a double or float.
If anyone can clue me in, I'd appreciate it.
-Garrett
Code:
[data] => Array
(
[E001] => 40.00
[E021] => 2.25
[E022] => 1.16
[E01S] => 0.00
[E012] => 0.00
[E09B] => 0.00
)
Now, these values can only have possible values of x.25, x.50, x.75 , x.00 or x. so I want to do a foreach loop through the array and determine if any of these values doesn't meet that criteria.
I've tried several different approaches including:
Code:
foreach( $_POST['data'] as $k => $v ) {
if ( ($v % .25) > 0 ) {
$site->raise_error( 'All data must be either .25, .50, .75, .00' );
}
}
I also tried:
Code:
foreach( $_POST['data'] as $k => $v ) {
$v = $v / .25;
if ( is_double($v) ) {
$site->raise_error( 'All data must be either .25, .50, .75, .00' );
}
}
Which didn't work either, I think because a division operator automatically makes it a double or float.
If anyone can clue me in, I'd appreciate it.
-Garrett
