Jump to content

[SOLVED] Multi-Dimensional Array


decypher

Recommended Posts

Html:

<html>
<head>
<title>Basic multi-dimensional array</title>
</head>
<body>

<h1> Basic 2D Array</h1>

<form action= basicmultiarray.php>
<table border = 1>
<tr>
  <th>First City</th>
  <th>Second City</th>
<tr>

<!-- note each option value is numeric -->

<tr>
  <tD>
  <select name = "CityA">
   <option value = 0>Indianapolis</option>
   <option value = 1>New York</option>
   <option value = 2>Tokyo</option>
   <option value = 3>London</option>
</seltect>
</td>

<td>
<select name = "CityB">
   <option value = 0>Indianapolis</option>
   <option value = 1>New York</option>
   <option value = 2>Tokyo</option>
   <option value = 3>London</option>
</seltect>
</td>
</tr>

<tr>
  <td colspan = 2>   
    <Input type = "submit"
           Value= "calculate distance">
  </td>
</tr>
</table>
</body>
</html>

 

PHP:

<html>
<head>
<title> distance Calculator</title>
</head>
<body>
<method = "POST">
<?php

$city = $_POST['array'];
$cityA = $_POST['cityA'];
$cityB = $_POST['cityB'];

$city = array("Indianapolis","New York","Tokyo","London");

$distance = array(
array (0, 648, 6476, 4000),
array (648, 0, 6760, 3470),
array (6476, 6760, 0, 5956),
array (4999, 3470, 5956, 0)
);

$result =$distance[$cityA][$cityB];
print "<h3>The distance between ";
print "$city[$cityA] and $city[$cityB]";
print " is $result miles.</3>";

?>

</body>
</html>

 

Problem is that when i do the query as such all I get is...'The distance between and is miles.' not gettin the city names or miles...any suggestions?

 

Many thanks in advanced

 

P.S This problem does keep re-occuring when all coding is right...Any reasons why the data doesn't show when I sumbit the button?

Link to comment
https://forums.phpfreaks.com/topic/61289-solved-multi-dimensional-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.