Retrieve the maximum value in the array & lt ;? Php $ tarray (1, 2, 3, 4, 5); $ resultarray_search (max ($ t), $ t); echo maximum value:. $ result; & nbsp ;? & Gt; Why is this result 4 vomiting blood ------ solution -------------------- max ($ t) is 5 & nbsp; $ r retrieve the maximum value in the array
$ T = array ('1', '2', '3', '4', '5 ');
$ Result = array_search (max ($ t), $ t );
Echo 'maximum: '. $ result;
?>
Why is the result 4 displayed?
Vomiting blood
------ Solution --------------------
Max ($ t) is 5
$ Result = array_search (5, $ t );
This is to find the element with the value of 5 in the $ t array and return the key corresponding to this element.
5 exists in this array and the key is 4. Therefore, 4 is returned as OK.
The array key starts from 0.
Change the last sentence of your program to echo 'maximum value key: '. $ result;
------ Solution --------------------
Echo 'maximum: '. max ($ t );
Why the array_search?
------ Solution --------------------
Discussion
$ T = array ('1', '2', '3', '4', '5 ');
$ Result = array_search (max ($ t), $ t );
Echo 'maximum: '. $ result;
?>
Why is the result 4 displayed?
Vomiting blood