0
<html>
<body>
<h2>xxxxxx!</h2>
<?php
    $score = array();
    exec("D:\Users\Owner\Documents\a2 2>&1 D:\Users\Owner\Documents\212.wav D:\Users\Owner\Documents\StartUp\23sw1.wav", $score);
    echo '<h3>Score </h3>';
    echo '<br />';
    echo 'xxxxxxx: ' . $score[0];
?>
</body>
</html>

The output of $score[0] is like 21 20 11 8 79 100 89. How can I split them? I am also interested in doing an average of it = ( 21 + 20+ 11+ 8 +79 +100+ 89)/7

  • possible duplicate of [how to convert array values from string to int?](http://stackoverflow.com/questions/9593765/how-to-convert-array-values-from-string-to-int) – teo van kot Mar 12 '15 at 05:26

2 Answers2

1

Do it like

$arr = explode(' ',$score[0]);
$average = array_sum($arr)/count($arr);
echo $average;
Mihir Bhatt
  • 3,019
  • 2
  • 37
  • 41
  • Actually, this did the trick: $average = array_sum($arr)/( count($arr) - 1); Yours counting up by 1. Do u need to set $average = 0 ? – user4661350 Mar 12 '15 at 17:05
  • Is this method reliable - explode(' ',$score[0]) - if there are white spaces here are there then will it be off? – user4661350 Mar 12 '15 at 17:25
0

//Create an array where have space, like this.

$scoreExp = explode(' ', $score[0]);
// start with 0 
$scorePlus = 0;
for($i=0;$i<count($scoreExp);$i++){
    $scored = $scoreExp[$i];    
    $scorePlus = $scorePlus + $scored;
}
echo $scorePlus/count($scoreExp);
Jakir Hossain
  • 2,457
  • 18
  • 23
  • 1
    Even if your answer may solve the initial question, you should also leave a short description and explain why and how your code fixes the initial problem. – user1438038 Jan 27 '17 at 14:27
  • code-only answers aren't useful for the community. Please look at [answer] – JimHawkins Jan 27 '17 at 20:03