Jump to content

Array ordering


shasto100

Recommended Posts

Hi guys, I have 4 arrays which contain a key and value for each, the array name does not matter:

 

$array10 = array(0 => 'D', 1 => 'E');
$array28 = array(0 => 'B', 1 => 'C');
$array33 = array(0 => 'A', 1 =>'B');
$array67 = array(0 => 'C', 1 => 'D');

 

The arrays could be given in any other,  but it has to be ordered so it goes A (start) to B to C to D to E (end), but it has to end like this (ignore the array name):

 

$array33 = array(0 => 'A', 1 =>'B');
$array28 = array(0 => 'B', 1 => 'C');
$array67 = array(0 => 'C', 1 => 'D');
$array10 = array(0 => 'D', 1 => 'E');

 

Any help greatly appreciated, spend around 4 hours going through the numerous array functions on php.net, didn't get anywhere :(

Link to comment
https://forums.phpfreaks.com/topic/166164-array-ordering/
Share on other sites

Thanks for replying. I have 4 random arrays (ignore the array name as this could be anything), each containing 2 values. I used A B C D E as I thought it might be easier to understand, but looking again i haven't really explained myself properly, sorry.

 

Start over

 

$ticket1 = ('departure' => 'Lime St', 'arrival' => 'Manchester');
$ticket2 = ('departure' => 'Manchester', 'arrival' => 'London');
$ticket3 = ('departure' => 'London', 'arrival' => 'Southampton');
$ticket4 = ('departure' => 'Southampton', 'arrival' => 'Dover');

 

You are given these tickets in any order.  As Lime St & Dover are only used once they are the start & end of the journey.  Does this make sense?

Link to comment
https://forums.phpfreaks.com/topic/166164-array-ordering/#findComment-876286
Share on other sites

You are given a number of tickets each containing a departure and arrival (no times are given).  The tickets are in a mixed order, I'm just looking for the best approach to get the tickets in order:

1) Get the ones which are start and end, eg: Lime St & Dover

2) Create a seemless journey, eg: Starting at Lime St, get the Manchester train. Arrival at manchester, next get the train to London.  Your next train is to Southampton etc etc.

 

I think I 1st have to get the first and last locations, then match the 1st location arrival to the 2nd location departure etc.  Hope you understand than better.

 

I'm not looking for a complete solution by any means, but the best way to go really as they are so many Array functions available.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/166164-array-ordering/#findComment-876297
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.