0

Hello friends I have two arrays called

var $conversion_rates; 

and

var $LastUpdate_rates;

now I am updating them in my class with values . If you do var_dump() both of them you get values like this

 echo "This is conversion rates<br>".var_dump( $this->conversion_rates = $rates_array);

array(1) { [11]=> float(507.6) } This is conversion rates

echo "This is conversion rates<br>".var_dump($this->LastUpdate_rates = $this->checkRatesFile());

array(1) { [11]=> string(6) "507.60" } This is LastUpdate Rates

Then I am trying to do is this

if( count(array_diff($this->conversion_rates, $this->LastUpdate_rates)) >0){
       //do something ......
}

The if statement is always true because the array value are different so I want to change one of the array to float what should I do

3
  • 1
    Directly comparing floats with (essentially) $float1 == $float2 is very prone to errors due to float (in)accuracy to begin with. A simple array_diff will probably never get you there. Commented Feb 27, 2014 at 9:14
  • Oh so what do you suggest I should do here ? Commented Feb 27, 2014 at 9:18
  • 1
    On a side note, var_dump() doesn't return a string, it writes directly to stdout. If you want it to get a string from it you'll have to use ob. (check php doc of ob_start()) Commented Feb 27, 2014 at 9:18

1 Answer 1

1

Try this

$a = "0.275";
var_dump($a);

Then try this;

$a = "0.275";
var_dump((float)$a);

And see what you can make of that;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.