PharaohInc
New Member
- Messages
- 8
- Reaction score
- 0
- Points
- 0
Ok,I'm having a problem. I have an array of arrays, the arrays inside the arrays are in that format shown below. What I want to do is take the shortest distance between the points but if they are in the same city the loop would discard them and move it to the next one that has the shortest distance to the point but not in the same city.
This is the keys of each of the normal arrays
$venue['city']
$venue['country']
$venue['xcoord']
$venue['ycoord']
The loops looks like it does below and there is a function that can calculate the distance between points already. The variable $startVenue has the same format as the normal arrays as well
The thing is if i take out the if statement with the city it works, giving points that are close but with the if statement for the city it gives me nothing, i have tried strcmp and it still does not work. I'm at wits end at what to do.
This is the keys of each of the normal arrays
$venue['city']
$venue['country']
$venue['xcoord']
$venue['ycoord']
The loops looks like it does below and there is a function that can calculate the distance between points already. The variable $startVenue has the same format as the normal arrays as well
PHP:
for($r=0;$r < 5; $r++)
{
$startVenue; // starting location or the first array
$venue1 = $startVenue;
$tour;
$venues; //contains the arrays with all the information of the venues
$shortestDistance = 999999999;
$index;
for($i=0;$i<sizeof($venues);$i++)
{
$dist = distance($venue1,$venues[$i]);
if(dist<$shortestDistance)
{
if($venue1['city']!=$venues[$i]['city'])
{
$shortestDistance = dist;
$index = $i;
}
}
}
array_push($tour,$venue1);
$venue1 = $venues[$index];
unset($venues[$index]);
array_values($venues);
}