Ex No: 12 Write a program to Sort Country Names in Array
Aim: To perform array processing using php
Algorithm
Step1: Design a webpage to get five Country Name and Capital Name.
Step2: On form submit check if array elements are set and not empty
   A) Get array values from POST method.
   B) Use for loop to sort the Country Name
   c) Display the Sorted Country Name and Capital Name.

index.html


<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>Sorted Country Name</title>
</head>
<body>
 <h3>Country and Capital Names</h3>
  <form id="arrayform" name="arrayform" method="POST" action="ex12.php">
  <table>
	<tr><th>Country Name</th><th>Capital Name</th></tr>
	<tr>
	  <td><input type="text" name="coname[]" required></td>
	  <td><input type="text" name="capname[]" required></td>
	</tr>
	<tr>
	  <td><input type="text" name="coname[]" required></td>
	  <td><input type="text" name="capname[]" required></td>
	</tr>
	<tr>
	  <td><input type="text" name="coname[]" required></td>
	  <td><input type="text" name="capname[]" required></td>
	</tr>
	<tr>
	  <td><input type="text" name="coname[]" required></td>
	  <td><input type="text" name="capname[]" required></td>
	</tr>
	<tr>
	  <td><input type="text" name="coname[]" required></td>
	  <td><input type="text" name="capname[]" required></td>
	</tr>
	<tr><td colspan="2"><input type="submit" value="Process Array"/></td></tr>
  </table>
 </form>
</body>
</html>                   

ex12.php


<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>Array Processing</title>
</head>
<body>
 <?php    
#starting point of the php program
if(isset($_POST["coname"]) && isset($_POST["capname"]))
{
 $coname = $_POST["coname"];
 $capname = $_POST["capname"];
 $size = count($coname);
 for($i=0;$i<$size;$i++)
 {
  for($j= $i+1;$j<$size;$j++)
  {
   if(strcmp($coname[$i],$coname[$j])>0)
   {
    $cotmp = $coname[$i];
    $coname[$i] = $coname[$j];
    $coname[$j] = $cotmp;
    $capnametmp = $capname[$i];
    $capname[$i] = $capname[$j];
    $capname[$j] = $capnametmp;
   }		
  }
 }
 echo "<h1>Sorted Country Name and Capital</h1>";
 for($i=0;$i<$size;$i++)
 {
  echo "$coname[$i] - $capname[$i] <br>";
 }
}
 ?>
 </body>
</html>
                  
Result: Thus a webpage is designed using php to perform Array Processing.