开发者

calculations between two Multidimensional arrays

I have this code:

$id = new matrix(array(0=>array(1,0.5,3), 1=>array(2,1,4), 2=>array(1/3,1/4,1)));

$soma = $id->times($id)->sumRows();

That outputs this:

matri开发者_开发百科x Object ( [numbers] => Array ( [0] => Array ( [0] => 12.75 [1] => 22.3333333333 [2] => 4.83333333333 ) ) [numColumns] => 3 [numRows] => 1 )

and:

$total = $id->times($id)->sumRows()->sumTotal($id);

That outputs this:

matrix Object ( [numbers] => Array ( [0] => Array ( [0] => 39.9166666667 ) ) [numColumns] => 3 [numRows] => 1 ) 

Now, i am trying to make:

foreach ($soma as $value){
    $final = (int)$value/(int)$total;
    print_r ((int)$final);
}

The output will be 000.

Must be:

12.75/39.9166666667 = 0,3269230769230769 
22.3333333333 / 39.9166666667 = ...
and so on

Thanks!


Just some ideas, without really knowing much about the matrix class...

  1. All those (int)s should probably be (float)s, as you seem to want a non-int answer.
  2. $value is itself an object, so you'll probably need to use $value['numbers'][0][0 or 1 or 2]. Same goes for $total.


the issue is solved :

documentation:

get_data($..)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜