Wednesday 3 March 2021

Write a program to sort array of elements using bubble sort Using PHP

 

Write a program to sort array of elements using bubble sort

Example : 



<title>PHP : Write a program to sort array of elements using bubble sort.</title>


<?php

/* Write a program to sort array of elements using bubble sort. */

$n=array(9,8,7,6,5,4,3,2,1,0);

$temp=0;

for($b=0;$b<=9;$b++)

{

if($n[$b]<$n[$b-1])

{

$temp=$n[$b];

$n[$b]=$n[$b-1];

$n[$b-1]=$temp;

}

}

print"After Sorting";

for($a=0;$a<=8;$a++)

{

print"<br>".$n[$a];

}

?>


OutPut : 

After Sorting
8
7
6
5
4
3
2
1
0

No comments:

Post a Comment