Write a program to print largest number from array in php

In this article, We’ll write a program to print a largest number from array in php without using php in-built function.

First, We’ll assign some random elements in array variable i.e $array




    $array = [12, 45, 33, 34, 3, 2, 89, 76, 22];
    $var   = 0;
    foreach ($array as $element) { 

     if ($var <= $element)
     $var = $element;

    }	
    echo $var; // Output 89

That’s it!. Please share your thoughts or suggestions in the comments below.

Leave a Reply

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