HI, I need some help with code for finding the highest value of an array of variables. Forexample the variables are $this->test[1] $this->test[2] and $this->test[3] $this->test[1] = 2 $this->test[2] = 5 $this->test[3] = 1 How can I find the variable that has the highest value?. its obvious that $this->test[2] is the highest but how can we find this out using code? Many thanks
PHP: $intArray = [1, 2, 3, 4, 5];$highest = 0;foreach($intArray as $key => $value) { if($value > $highest) { $highest = $value; }}echo $highest; // 5 That's a basic check with a loop, I'm sure there's other ways that I can't recall off the top of my head.
you should use this: PHP: $this->test = [2,5,1];$max = max($this->test); //will return 5 because its the highest int in your array :)