How to Find Largest Element in an Array

How to Find Largest Element in an Array
  • Make an array with random integer elements.
  • Sort it an ascending order
  • Print top value using array_slice function.
<?php
$arr = array ( 11, 53, 14, 2, 41, 5, 10, 17, 60, 28, 0 ); 
rsort($arr);
$top_elements = array_slice($a, 0, 5); 
print_r($top_elements);
?>

15 Replies to “How to Find Largest Element in an Array”

  1. I actually wanted to write down a small comment to be able to say thanks to you for those lovely items you are giving out on this website. My particularly long internet lookup has finally been rewarded with extremely good tips to exchange with my companions. I ‘d believe that we site visitors actually are rather endowed to exist in a useful place with so many brilliant people with useful secrets. I feel very much privileged to have encountered the website and look forward to tons of more cool times reading here. Thanks a lot once again for everything.

  2. I just want to say I’m beginner to blogging and site-building and definitely enjoyed your web blog. Probably I’m going to bookmark your blog . You absolutely have terrific articles. Thanks a bunch for sharing your webpage.

Leave a Reply

Your email address will not be published. Required fields are marked *