Change language

# PHP program for finding maximum and minimum in an array

|
Examples:
`Input: arr [] = {2, 3, 1, 6, 7} Output: Maximum integer of the given array: 7 Minimum integer of the given array: 1 Input: arr [] = {1, 2, 3, 4, 5} Output: Maximum integer of the given array: 5 Minimum integer of the given array: 1 `
Approach 1 (simple ):we just loop through the array, find its maximum and minimum.``` // Returns the maximum in the array function getMax ( \$array ) { \$n = count ( \$array ); \$max = \$array [0]; for ( \$i = 1; \$i < \$n ; \$i ++) if ( \$max < \$array [ \$i ]) \$max = \$array [ \$i ]; return \$max ; }   // Returns the maximum in the array function getMin ( \$array ) { \$n = count ( \$array ); \$min = \$array [0]; for ( \$i = 1; \$i < \$n ; \$i ++) if ( \$min > \$array [ \$i ]) \$min = \$array [ \$i ]; return \$min ; }   // Driver code \$array = array (1, 2, 3, 4, 5); echo (getMax ( \$array )); echo ( "" ); echo (getMin ( \$array )); ?> Output:5 1 Approach 2 (Using library functions):we use library functions to find the minimum and maximum. Max():max() returns the parameter value that is considered the “highest” according to standard comparisons. If multiple values ​​of different types evaluate to equal (for example, 0 and "abc"), the first value supplied to the function will be returned. Min():min() returns the parameter value which is considered “lowest” according to standard comparisons. If multiple values ​​of different types evaluate to equal (for example, 0 and "abc"), the first value supplied to the function will be returned. < ? php \$array = array (1, 2, 3, 4, 5); echo (max ( \$array )); echo ( "" ); echo (min ( \$array )); ?> Output:5 1 ```
``` ```
``` (adsbygoogle = window.adsbygoogle || []).push({}); Shop Learn programming in R: courses\$ Best Python online courses for 2022\$ Best laptop for Fortnite\$ Best laptop for Excel\$ Best laptop for Solidworks\$ Best laptop for Roblox\$ Best computer for crypto mining\$ Best laptop for Sims 4\$ (adsbygoogle = window.adsbygoogle || []).push({}); Latest questions NUMPYNUMPY psycopg2: insert multiple rows with one query 12 answers NUMPYNUMPY How to convert Nonetype to int or string? 12 answers NUMPYNUMPY How to specify multiple return types using type-hints 12 answers NUMPYNUMPY Javascript Error: IPython is not defined in JupyterLab 12 answers All questions (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ```
``` ```
``` News 19/08/2022 Study: iOS bug prevents VPN from fully encrypting traffic 19/08/2022 Media: production of systems-on-a-chip M2 Pro and M2 Max will begin at the end of 2022 19/08/2022 YouTube will automatically add watermarks to Shorts videos Wiki __del__ Python OpenCV | cv2.putText () method __del__ numpy.arctan2 () in Python __del__ Python | os.path.realpath () method around Python OpenCV | cv2.circle () method cvtcolor Python OpenCV cv2.cvtColor () method Python functions Python - Move item to the end of the list Counters time.perf_counter () function in Python __dict__ Check if one list is a subset of another in Python __del__ Python os.path.join () method © 2017—2022 Python Engineering Hub EN | ES | DE | FR | IT | RU | TR | PL | PT | JP | KR | CN | HI | NL Python.Engineering is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com Python Loops Counters NumPy NLP Regular Expressions Wiki Tech news Python Wiki StackOverflow PHP JavaScript Books All books Computations Development Cryptography For dummies Big Data document.addEventListener("DOMContentLoaded", () => { let arrayCode = document.querySelectorAll('pre'); arrayCode.forEach(element => { element.classList.add("prettyprint"); }); }); window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-Q022WLXW4X'); ```