I have some array value returns from the database like
$rate =
["1.55","1","1","1"]
["2.55","2.55","2.55","2.55"]
["1","1","1","1"]
["1.2","1.21","1.2","1.2"]
My Actual DB Value
array(4) {
[0]=>
array(1) {
["rate"]=>
string(20) "["1.55","1","1","1"]"
}
[1]=>
array(1) {
["rate"]=>
string(29) "["2.55","2.55","2.55","2.55"]"
}
[2]=>
array(1) {
["rate"]=>
string(17) "["1","1","1","1"]"
}
[3]=>
array(1) {
["rate"]=>
string(29) "["1.55","2.55","3.55","4.56"]"
}
}
So the calculation is
1.55+2.55+1+1.2 =6.3/4 =1.57
1+2.55+1+1.21 =5.76/4 =1.44
1+2.55+1+1.2 =5.75/4 =1.43
1+2.55+1+1.2 =5.75/4 =1.43
How to get an average from those values and the result is something like
["1.57","1.44","1.43","1.43"]
What I have tried so far
foreach($dibor_data as $key=>$value){
if(array_key_exists($key,$sum)){
$repeat[$key] = $repeat[$key]+1;
$sum[$key] = $sum[$key] + json_decode($value['rate']);
}
}