Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Monday, February 6, 2023

6. Create an associative array using the countries as keys, the cities as values and transform it into 2-dimensional array and display the data as a table

 

<html>

<body>

<?php

$a_array=array("India"=>"NewDelhi","Afghanistan"=>"Kabul","Australia"=>"Canber ra","Bangladesh"=>"Dhaka","Brazil"=>"Brasilia","Canada"=>"Ottawa","China"=>"Be ijing","France"=>"Paris","Japan"=>"Tokyo","Thailand"=>"Bangkok");

$j=0;

foreach ($a_array as $x=>$x_value)

{

$newarray[0][$j]=$x;

$newarray[1][$j]=$x_value;

$j=$j+1; }

echo "<table border=1>";

echo "<tr><th>Country</th><th>Capital</th></tr>";

 

for($k=0;$k<$j;$k++)

{echo "<tr><td>".$newarray[0][$k]."</td>"; echo "<td>".$newarray[1][$k]."</td></tr>";

}

echo "</table>";

?>

</body>

</html>

 




 

No comments:

Post a Comment