How to divide two values of an array?

Asked

Viewed 176 times

0

I have the following code, where only index 0 is string:

        $row[0] = $row[0];
        $row[1] =(float) $row[1];
        $row[2] =(float) $row[2];
        $row[3] =(float) $row[3];
        $row[4] =(float) $row[4];
        $row[5] =(float) $row[5];
        $row[6] =(float) $row[6];

I need to divide one index by the other, I’m trying like this:

       $a = $row[5] / $row[6];
        $row[7] =$a;

However, my table does not load.
Note: The strange thing is that if I make a sum it works.

What is going on?

  • 1

    Some division by zero?

  • @rray, yes some values are 0.

  • 1

    Do you want to automate this with a repeat loop for example ? or just split the values you choose ? it was not very clear your goal , could give an example of values for variable $row to test here

  • 1

    Give a "print_r($Row[5] / $Row[6]);" ve if it returns an error and put it here.

  • @Viniciusshiguemori, basically I need to do a percentage calculation, which would be $Row[2] + $Row[3] + $Row[5] = $total, then add $Row[2] + $Row[5] / $total.

  • 2

    You have to create for example a if if the divisor $row[2] + $row[5] / $total // <- $total é o divisor; is equal to zero skip this account, because according to the rules of mathematics it cannot be divided by 0

  • 1

    @Victorpereira , giving division error by 0

  • @Viniciusshiguemori, I think that’s right, I’ll try.

  • What is the logic of this: $Row[0] = $Row[0]; ?

  • @Lucascarvalho, is to assemble the lines of the Datatable. https://datatables.net/development/server-side/php_mysql

  • @Gabrieltobias makes sense your first snippet of code? You’re assigning the array position to the same thing!

  • What do these divisions and the values themselves mean? That seems to me a XY problem

  • @Isac, it’s a production performance calculation.

  • @Viniciusshiguemori, really, the problem was the division by 0, I made the condition and it worked. Thank you all for the answers!

Show 9 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.