PHP Searching and Sorting in Array

Program 1

<html>
    <head><title>Array in PHP Application</title>
    <body>
  
  <pre>
    <center>
<?php
     $numbers=array(10,5,6,12,56,77,89);
     $s=12;
       $temp=false;
        for($i=0;$i<count($numbers);$i++)
     {
            if($s==$numbers[$i])
            {
                $temp=true;
                break; 
            }   
     }
     if($temp==true)
         echo "<br><font color=green size=5> Searching success</font>";
        else
        echo "<br><font color=red size=5> Element not found</font>";
?>

</pre>
        </center>
</body>
</html>

Program 2

<html>
    <head><title>Array  Sorting in PHP Application</title>
    <body>
  
  <pre>
    <center>
    
<?php
     $numbers=array(10,5,6,12,56,77,89);
     
     
     for($i=0;$i<count($numbers);$i++)
     {
        for($j=$i+1;$j<count($numbers);$j++)
        {
               if($numbers[$j]<$numbers[$i])
               {
                  $temp=$numbers[$i];
                  $numbers[$i]=$numbers[$j];
                  $numbers[$j]=$temp;
               }
        }
     }
     echo "<br> Sorted elements : ";
     for($i=0;$i<count($numbers);$i++)
     {
         echo "<br>".$numbers[$i];
     }
?>

</pre>
        </center>
</body>
</html>

 

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

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