liamloveslearning Posted January 27, 2011 Share Posted January 27, 2011 Hi there Got a problem needs a solution, basically a booking system has been built (by me) and works great except for the checking availablity Basically they can do drives in a car (in any order) so I need to try all possible combinations. one idea I had was to use an array holding the availability for each slot so that it looks like slotArray=array("ABC","AC","C","A","BC","AB","ABC" ...etc) looking for drives A and B so check if slotArray[1] contains A and Slot Array 2 contains b or vice versa what i need to do is work out all the possible orders of a string ABCDE (there will be 120 of them) so I can systematically check the order anyone have a function that will do this? Link to comment https://forums.phpfreaks.com/topic/225864-booking-system-woes/ Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 adapted from http://docstore.mik.ua/orelly/webprog/pcook/ch04_26.htm function pc_permute($items, $perms = array( )) { if (empty($items)) { print join(' ', $perms) . "\n"; } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); pc_permute($newitems, $newperms); } } } $vals = array('A','B','C','D','E'); $res = pc_permute($vals); print_r($res); Link to comment https://forums.phpfreaks.com/topic/225864-booking-system-woes/#findComment-1166055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.