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

  • Home
  • SEARCH
  • 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 6637679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:20:36+00:00 2026-05-25T23:20:36+00:00

Sorry for asking probably a basic question, but I’m having a blackout. If I

  • 0

Sorry for asking probably a basic question, but I’m having a blackout.

If I have an array of arrays:

Array
(
    [appsversion] => Array
        (
            [0] => appsversion='6.1.0.33'
            [1] => appsversion='6.1.0.40'
        ),
    [osversion] => Array
        (
            [0] => osversion='6.1.0.53'
            [1] => osversion='6.1.0.42'
        )
)

how do I please construct an SQL condition with OR and AND of it?

I.e. for something like:

    $condition = '';
    foreach ($CONDITIONS as $key => $value) {
        # XXX I'm so lost here XXX
    }

    $sql = sprintf('select %s from mytable where %s', $condition);
    $sth = $pg->prepare($sql);
    $sth->execute();

I need the constructed string

    (appsversion='6.1.0.33' OR appsversion='6.1.0.40') AND
    (osversion='6.1.0.53' OR osversion='6.1.0.42') 

or:

    appsversion in ('6.1.0.33', '6.1.0.40') AND
    osversion in ('6.1.0.53', '6.1.0.42') 

Please give me few hints – to get my brain started again 🙂

  • 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-05-25T23:20:37+00:00Added an answer on May 25, 2026 at 11:20 pm

    There:

    $where = array();
    foreach ($conditions as $values) {
        $where[] = '('.implode(' OR ', $values).')';
    }
    $string = implode(' AND ', $where);
    

    Yields:

    (appsversion='6.1.0.33' OR appsversion='6.1.0.40') AND (osversion='6.1.0.53' OR osversion='6.1.0.42')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for asking a basic question like this but I've been reading on this
sorry for re-asking, but i have new circumstances. here was my question .net -
Sorry for asking silly question.. I have an array with class objects like: Class
Guys, sorry for asking basic question, i have a problem here where I have
Sorry for asking a stupid question but I have a problem that makes me
Sorry for the basic question - I'm a .NET developer and don't have much
Sorry for asking this question, but I searched all Java-related questions, but I got
Sorry for asking what seems like such an obvious question. I have an adapter
Sorry for asking a question about something I don't know much about, but I've
sorry for asking this, but i'm runnin' out of ideas i have this table:

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.