Multiplication with first array value returning 0 always

142 views Asked by At

I am getting a value from database 67.00€ .I need to multiple this value with an integer. So, used explode function of php to convert this to array and stored it in a variable $result.

print_r() is as follows:

Array
(
    [0] => 67
    [1] => 00€
)

Now, if i'm multiplying the first value of this array with any value, result is always 0. like:

$result[0]*12

i also tried to convert the first value to integer by using (int) $result[0] and intval($result[0]). Both output 0

What i am doing wrong?

1

There are 1 answers

5
Naincy On

Try this:

intval($result[0])* 12

I have tried this and it worked for me. Please create a new file and run in localhost other that your project.

test.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$str = '67.00$';
$result = explode('.',$str);
print_r($result);

$ans= intval($result[0])*12;    // or  $ans=($result[0])*12;  both worked
echo 'Answer-->'.$ans;   // 804
?>

I don't know what you doing wrong. I hope from this you may able to detect your err.