shasto100 Posted July 16, 2009 Share Posted July 16, 2009 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 More sharing options...
Ken2k7 Posted July 16, 2009 Share Posted July 16, 2009 So what am I working with? What do you mean ignore the array names? If that's how your code looks, it doesn't matter what order your variables are in. It just matters how you use them. Not sure how much more help I can be. Link to comment https://forums.phpfreaks.com/topic/166164-array-ordering/#findComment-876280 Share on other sites More sharing options...
shasto100 Posted July 16, 2009 Author Share Posted July 16, 2009 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 More sharing options...
shasto100 Posted July 16, 2009 Author Share Posted July 16, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.