PHP Examples - Arrays

PHP Examples 

 Arrays

Program:
<html >
<head>

<title>PHP Example 5 : ARRAYS</title>
</head>

<body>
<?php
 
 echo "PHP Example 5";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"ARRAYS";
 echo"</h1>";
 echo"<br/>";

 $array1 = array(5,3,7,6,1,2,9);  //Creating array 
 $array1[] = 8;
 $array1[] = 4;
 
 $n=count($array1); // Counting no of elements
 
 echo"<br/><b> Before sorting: </b> ";
 for($i=0;$i<$n;$i++)  //Printing array elements 
  echo $array1[$i]." ";  

 for($i=0;$i<$n;$i++)  //Sorting
 for($j=$i+1;$j<$n;$j++)
 {
  if($array1[$i]>$array1[$j])
  {
   $temp=$array1[$i];
   $array1[$i]=$array1[$j];
   $array1[$j]=$temp;
   }
 }
 
 echo"<br/> <b>After sorting: </b>";
 for($i=0;$i<$n;$i++)
  echo $array1[$i]." ";
 echo"<br/>";

 $arraysum = array_sum($array1);  // Calculating sum of the elements in the array 
 echo"<br/><b> Sum of the elements : </b>$arraysum";
 echo"<br/>";
 
 echo "<br/><b>Checking whether element is present in the array or not...</b>";
 if(in_array(5,$array1))      // Checking whether element is present in the array or not
  echo "<br/>5 is present in the array... ";
 else 
  echo "<br/>5 is not present in the array... ";
 echo"<br/>";

 echo "<br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>



Output:






3 comments:

  1. Fantastic insights! Your article beautifully captures the essence of choosing the right Website Designing Company in Delhi. It's so important to find a partner who understands both the technical and creative aspects of web design, and your tips will certainly help businesses make informed decisions. Keep up the great work!

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...