3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php //could do to change this as not good for internet exploder. if (isset($_POST['calc'])) { //this function will return the value of the field if it was a number, else it will return 0 and reduce the master divide fo the average. function numCheck(&$masterDiv,$a){ if(ctype_digit($a) { return $a; } else{ --$masterDiv; return 0; } //number to divide with to get the average $masterDiv = count($_POST) - 1;//minus your input button //running total of values $runningTotal = 0; //get all the keys of the post array $keys = array_keys($_POST); //loop through based on the count of the $_POST for($i=0 ; $i < count($_POST) ; ++$i) { //as the $key array is based exactly on the $array array the key is pos $i in the array: $theKey = $keys[$i]; //now we have the associative key we can easily get the value $theValue = $array[$theKey]; //now do what ever you want with the data, provided the current is not the calc button if($theKey != 'calc') { //using the function we built at the top this should add the value sent to the runningTotal if it is a number, else it will return a zero for the runningTotal and reduce by 1 the masterDivide meaning it will not be including when calculating the average $runningTotal += numCheck($masterDiv,$theValue); } } //now calculate the average based on the mastser divide and running total. $ave=$runningTotal / $masterDiv; }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.4.32
Parse error: syntax error, unexpected '{' in /in/hFZfj on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '{' in /in/hFZfj on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/hFZfj on line 8
Process exited with code 255.