Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:12:50+00:00 2026-06-16T05:12:50+00:00

Having created an array of values using a MySQL query, I need to check

  • 0

Having created an array of values using a MySQL query, I need to check if they are all at least equal to a given value. This is for checking room availability in a hotel.

First I do the the MySQL query:

foreach( $datearray as $value ) {
$query_avail = "SELECT cupo, ex_cupo.room_id FROM ex_cupo JOIN ex_rooms ON ex_cupo.room_id=ex_rooms.room_id  AND ex_rooms.room_id = '$room_id' AND dt = '$value'";
$avail = mysql_query($query_avail, $MySQL_extranet) or die(mysql_error());
$row_avail = mysql_fetch_assoc($avail);
   $availresult[] = $row_avail['cupo'];
}

“Cupo” is the number of rooms available for a given date, so $availresult will be an array of the number of rooms available across a range of dates.

Now if someone wants to book (say) 2 rooms for those dates, I need to ensure that each value in the array is at least 2. For example, if there are 5 dates in the range and they are 2, 2, 1, 2, 2, I need to return false, but if they are 2, 2, 2, 2, 2 or 2, 2, 3, 2, 2, I need to return true.

How do I do that? (I hope I explained it well enough.)

Obviously the choice of 2 is just an example. It will normally be a variable called $numrooms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:12:51+00:00Added an answer on June 16, 2026 at 5:12 am
    $testArray = array(2,2,2,2,1,2);
    
    $valid = array_reduce(
        $testArray,
        function ($match, $value) {
            return $match && ($value >= 2);
        },
        TRUE
    );
    var_dump($valid);
    

    How to pass $numrooms through:

    $testArray = array(2,2,2,2,1,2);
    $numrooms = 2;
    
    $valid = array_reduce(
        $testArray,
        function ($match, $value) use ($numrooms) {
            return $match && ($value >= $numrooms);
        },
        TRUE
    );
    var_dump($valid);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of difficulty using the values in a PHP array for
I'm having trouble displaying my mysql table using php code. All it displays is
I have created an empty json object having an array itemlist(which further contains itemid
Having created dropdown lists using ViewBag which is working in an edit form. How
I'm having a problem of storing multiple input value in Java. First, I'm using
I need button to begin a mysql query to then insert the results into
I'm having difficulty in retrieving values from a Json array. I have a Json
Having problems with a MySQL query. Only returning the results for the first item
I am having difficulty updating a range of columns using mysql. My overall goal
I am having some trouble with multidimensional array and its value. What i am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.