[英]calculations between two Multidimensional arrays
我有以下代碼:
$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();
輸出如下:
matrix Object ( [numbers] => Array ( [0] => Array ( [0] => 12.75 [1] => 22.3333333333 [2] => 4.83333333333 ) ) [numColumns] => 3 [numRows] => 1 )
和:
$total = $id->times($id)->sumRows()->sumTotal($id);
輸出如下:
matrix Object ( [numbers] => Array ( [0] => Array ( [0] => 39.9166666667 ) ) [numColumns] => 3 [numRows] => 1 )
現在,我正在嘗試:
foreach ($soma as $value){
$final = (int)$value/(int)$total;
print_r ((int)$final);
}
輸出將為000。
一定是:
12.75/39.9166666667 = 0,3269230769230769
22.3333333333 / 39.9166666667 = ...
and so on
謝謝!
只是一些想法,對matrix
類的了解並不多。
(int)
都應該是(float)
,因為您似乎想要一個非整數的答案。 $value
本身是一個對象,因此您可能需要使用$value['numbers'][0][0 or 1 or 2]
。 $total
。 問題已解決:
說明文件:
get_data($..)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.