Searching and Sorting using inbuilt Function in PHP
Program 1
<html> <body> <center> <pre> <?php // Example of in_array function // $myar=[5,2,20,10,'40',60,70]; // $n=40; //echo in_array($n,$myar); // if(in_array($n,$myar,true)) // echo "<font color=green size=5>Searching Success</font>"; // else // echo "<font color=red size=5>Searching not success</font>" // Example of array_search function // $myar=[5,2,20,10,40,60,70]; // echo array_search(60,$myar); // if(array_search(120,$myar)>=0) // echo "<font color=green size=5>Searching Success</font>"; // else // echo "<font color=red size=5>Searching not success</font>" // Sorting of array //$myar=[5,2,20,10,40,60,70]; // sort() asc //rsort desc // echo "<br>Before Sorting"; // for($i=0;$i<count($myar);$i++) // { // echo"<br>".$myar[$i]; // } // //sort($myar); //rsort($myar); // echo "<br>After Sorting"; // for($i=0;$i<count($myar);$i++) // { // echo"<br>".$myar[$i]; // } $myar=[5=>"Vishal",2=>"Ashok",4=>"Rahul",3=>"Kamal",1=>"Nilesh"]; echo "<br>Before sorting"; print_r($myar); echo "<br>After sorting"; //asort($myar); // sorting according to value in asc // arsort($myar); // sorting according to value in desc // ksort($myar); // sorting according to key in asc krsort($myar); // sorting according to key in desc print_r($myar); // Array ?> </pre> </center> </body> </html>