从数组中的数据组合中检索结果

I'm hoping someone could point me in the right direction with this.

I need to use an array like this to find out if there the following combination is possible:

Customer searches for 2 rooms and 4 guests. In the example array it should be possible. But if the customer searches for 2 rooms and 5 guests it 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 will be a "greedy algorithm".

The generic algorithm for you case will be:

1. Take `$rooms` amount items with max number of beds from your array (array_walk or do some presorting by key)
2. If total amount of `number_of_beds` greater or equals  return true, else - false :)

You try to make a matching for it:

1. Select the (unselected) room with most beds available
2. If the number of beds you have altogether is greater or equal the numer requested, you are done. 
3. If the number of rooms selected is smaller than the limit, Continue at 1. 
4. Else the request has failed.

That way cou generate a matching for the request of your user, and if you cannot satifsy the demand you can tell him.

Another approach, useful if you expect many requests like this on the same page load would be to parse the rooms available and count how many 1-, 2-, .. n-Bed Rooms you have and then you can count the maximum number of beds you have by multiplying bedcount and number of rooms. This will outperform the greedy algorithm, but requires some preparation.