如何在php中通过索引动态循环获取数据?



我有数据数组动态,

$methods = [];
$result [] = ''; //result callculate save this variable;
foreach($data as $key=>$val){
$methods[]= $val['list_method'];
} 

我有一个数组,我正在循环,结果如下:

Array
(
[0] => Array
(
[rekomendasi] => 1
[select] => 236
[method] => Array
(
[0] => Array
(
[id] => 0
[rating] => 0
)
[1] => Array
(
[id] => 629
[rating] => 443.2
)
)
)
[1] => Array
(
[rekomendasi] => 1
[select] => 234
[method] => Array
(
[0] => Array
(
[id] => 620
[rating] => 343.43
)
[1] => Array
(
[id] => 628
[rating] => 345.772
)
)
)
)
1
在本例中,我根据索引进行计算。我做了一个这样的示例:
$result1 = 1 / (1 + (pow( 10 , ( index[0][method][0][rating] - index[0][method][1][rating])/400);
$result2 = 1 / (1 + (pow( 10 , ( index[1][method][0][rating] - index[1][method][1][rating])/400);

以前我做了代码,但我仍然对如何使计算动态感到困惑?

感谢

尝试下一个代码…

$result = []; //set result as an array;
foreach($data as $key=>$val){
$result[] = Ratings($val["method"]); // save the results in the array
}
print_r($result); // print the $result array

// function Ratings to hold the equation 
function Ratings($method){
$calculate = 1 / (1 + (pow( 10 , ( $method[0]["rating"] - $method[1]["rating"])/400);
return $calculate;
}

相关内容

  • 没有找到相关文章

最新更新