PHP Get Max Value From Array | PHP Tutorial

[ad_1]

PHP get the max/maximum/largest value from array. This tutorial has the purpose to explain to you several easy ways to find or get the maximum or largest value from an array in PHP.

Here, we will take e.g. PHP gets the maximum value in an array, get the largest number in the array PHP without a function or get the max value from an array in PHP using for loop

PHP find the highest value in an array

We can use the PHP max() function, which is used to find the largest number from an array in PHP.

Before we use the take examples, you must know about the PHP max() function.

PHP max() function

The max() function is inbuilt PHP function, which is used to find the numerically maximum or highest value in an array or find maximum or highest value of given specified values.

Syntax

 max(array)  
 or
 max(value1, value2, value3 … valueN)

Example – 1 Get max value in array PHP using max() function

Let’s take the first example, we will use the PHP max() function to find the maximum value in the array. Let’s see the example below:

<?php

$array = [1, 10, 50, 40, 2, 15, 100];

$res = max($array);

print_r($res);

?> 

The output of the above program is: 100

Example – Find largest number in array php without function

Let’s take the second example, in this example, we will find or get the largest or maximum number in array PHP without function. Let’s see the example below:

<?php

$array = array(1000,400,10,50,170,500,45);

$max = $array[0];

foreach($array as $key => $val){

    if($max < $val){

        $max = $val;
        
    }
}	

print $max;

?> 

The output of the above program is: 1000

Example – 3 PHP get max or highest value in array using for loop

Let’s take the third example, to find the maximum or largest or highest value in array PHP without using any function. Let’s look at the examples below:

<?php 

$array = array(500, 20, 55 ,165, 456, 78, 75);


$max = 0;

for($i=0;$i<count($arr);$i++)
 {
    if ($arr[$i] > $max)
	{
        $max = $arr[$i];
    }
}

print $max;

?>

Conclusion

Through this tutorial, we have learned how to find or get max value or elements from array in PHP.

Recommended PHP Tutorials

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00
نيك فى المساج abdulaporn.info فلم سكس لبناني
secretary xvideo pornborn.mobi animal and girl sex video
محجبة هايجة yubosp.com سحاق مايا خليفه
xnxxindean youporner.net xnxximages
nayanthara xvideo tubzolina.mobi pornstar list
صور سكس نياكه tinatube.net اكبربزاز
xxx indian sexy video orgyvids.info desi nude outdoor
افلام جنسيه مترجمه عربي pornclassic.info ام تتناك من صديق ابنها
www xnxx sex.com justerporn.mobi xxx2018
ولد ينيك امه مصري hqtube.org افلام سكس بث مباشر
x vidoi lamboborn.mobi indian xxx video com
اجمل نيك فى الطيز radarporn.com نيك اجنبى
passion hentai hentaicamz.com most popular hentai
youporn india indianbluetube.com spicyplumpers
xxx dilli big-porn-house.com sexi video in hindi