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 6787243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:20:34+00:00 2026-05-26T17:20:34+00:00

Array output from multiple select option Array ( [q] => Array ( [0] =>

  • 0

Array output from multiple select option

Array
(
    [q] => Array
        (
            [0] => monkey
            [1] => pig
            [2] => dog
            [3] => banana
            [4] => apple
            [5] => mango
            [6] => lavender
            [7] => magnolia
            [8] => marigold

        )

)

The code

$queryArray  = array_map("secure", $_GET['q']);
$inArray     = array();

foreach ($queryArray as $key) {
    $inArray[] = 'animals="' . $key . '"';
}

$sql = 'SELECT * FROM kids WHERE ' . implode(' AND ', $inArray) . '';
echo $sql;

Question :

How do I group the current array to be

animals = monkey,pig,dog
fruits  = banana,apple,mango
flowers = lavender,magnolia, marigold

Maybe filter the value manually or if in_array monkey,pig,dog is animals.

and make a correct MySQL statement to get something like this

SELECT * 
FROM kids 
  WHERE 
   (animals="monkey" OR animals="pig" OR animals="dog")
AND 
   (fruits="banana" OR fruits="apple" OR fruits="mango") 
AND 
   (flowers="lavender" OR flowers="magnolia" OR flowers="marigold")

Let me know.

  • 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-26T17:20:35+00:00Added an answer on May 26, 2026 at 5:20 pm

    You can use PHP associative array to store the query like this:

    $inArray['animals'] = SELECT * FROM kids WHERE 
                          (animals="monkey" OR animals="pig" OR animals="dog")
    
    $inArray['fruits']  = SELECT * FROM kids WHERE
                          (fruits="banana" OR fruits="apple" OR fruits="mango") 
    
    $inArray['flowers'] = SELECT * FROM kids WHERE
                         (flowers="lavender" OR flowers="magnolia" OR flowers="marigold")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of output from a database. I am wondering what the
How Create multiple array from an array and concatenate each elments? I have an
I am trying to select multiple rows from the database and then separate the
$jj_post is the array output debug via print_r() . This variable is an array
$arr = array(array(array())); foreach($arr as $subarr) { $subarr[] = 1; } var_dump($arr); Output: array(1)
I'm trying to write a 2d array into an output file, it's all working
I would like to know how to output an array of doubles to the
I'm using following peace of code to output an array: echo ======output without array_unique=====;
The output of my JSON call can either be an Array or a Hash.
I have have an array as follows: $row when I output the entire array

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.