Write a program to print smallest number from array in php

In this article, We’ll write a program to print a smallest 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 (empty($var))	 
     $var = $element;

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

    }	
    echo $var; // Output 2

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 *