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:
ReplyDeleteGreat post indeed and thanks for all the information, it was very helpful i really like that you are providing information on PHP and MYSQL
It is really a great work and the way in which u r sharing the knowledge is excellent.
ReplyDeleteDot Net Training Institute in Chennai
Software Testing Course in Chennai
Core Java Training in Chennai
PHP Certification in Chennai
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