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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -