PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 39: Write a program to print the largest element present in an array.

largest_element.php

<!DOCTYPE html>  
<html>
<head>	
	<title>PHP Programs TutorialDuniya.com</title>
</head>
<body>  
	<?php
		$arr = array(255, 101, 987, 715, 506);   
	
		$maximum = $arr[0];  
	
		for ($i = 0; $i < count($arr); $i++) 
		{
			if($arr[$i] > $maximum)  
			$maximum = $arr[$i];  
		}  

		print("Largest element present in given array: " . $maximum);
	?>  
</body>  
</html> 



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.