I know that actionscript and PHP are not the same a C++ (both are descendants of C), but this is how I would do it in actionscript...
Code:
function makeAverage(x) {
var count = 0;
var sum = 0;
if (x.length>0) {
for (var i = 0; i<x.length; i++) {
if (x[i]>=0) {
count++;
sum += x[i];
} else {
break;
}
}
}
if (count>0) {
return ("The average of the numbers is: "+(sum/count));
} else {
return ("No valad numbers were given.");
}
}
PHP would be fairly similar, except the variables would be denoted with "$", and I think array length is determined with "count()". Hope that helps.