Vikram Anand Bhushan
Vikram Anand Bhushan

Reputation: 4896

Conversion of string value in an array to float in php

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

Upvotes: 0

Views: 1114

Answers (1)

dkasipovic
dkasipovic

Reputation: 6120

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;

Upvotes: 1

Related Questions