php - Retrieving result from combination of data in an array -
i'm hoping point me in right direction this.
i need use array find out if there following combination possible:
customer searches 2 rooms , 4 guests. in example array should possible. if customer searches 2 rooms , 5 guests should return false.
<? $array[0]=>array( 'room_type'=>'single a', 'number_of_rooms'=>1, 'number_of_beds'=>1, ); $array[1]=>array( 'room_type'=>'twin a', 'number_of_rooms'=>1, 'number_of_beds'=>2, ); $array[2]=>array( 'room_type'=>'twin b', 'number_of_rooms'=>1, 'number_of_beds'=>2, ); ?>
right direction "greedy algorithm".
the generic algorithm case be:
1. take `$rooms` amount items max number of beds array (array_walk or presorting key) 2. if total amount of `number_of_beds` greater or equals return true, else - false :)
Comments
Post a Comment