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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:58:54+00:00 2026-05-27T01:58:54+00:00

I have an array of all options that will be in a select box:

  • 0

I have an array of all options that will be in a select box:

Array
(
   [2836] => 4 16:40:00
   [2835] => 3 13:20:00
)

There is a second array of options that have a particular flag in the DB:

Array
(
   [2835] => 3 13:20:00
)

How can I compare these two arrays to generate a select list that applies a particular class to the matches found in the arrays? I’d love some help thanks!

The view for my select list which receives the first array:

<select>
<?php foreach ($courses as $key=>$course): ?>   
<option id="<?php echo $key;?>">        
    <?php echo $course; ?>
</option>
<?php endforeach;?> 
</select>
  • 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-27T01:58:55+00:00Added an answer on May 27, 2026 at 1:58 am

    You can use array_intersect to find those values common for both arrays. Then in your foreach loop you can check if the current key (or value) is from matches array.

    $matches = array_intersect($arr1, $arr2);
    

    In the view file:

    <select>
    <?php foreach ($courses as $key=>$course): ?>   
        <option id="<?php echo $key;?>" class="<?php echo isset($matches[$key]) ? 'match' : '' ?>">        
            <?php echo $course; ?>
        </option>
    <?php endforeach;?> 
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a standard select box which I'm populating using jquery by appending options,
I have a method that will provide an array of model object. Some of
I have an array of values all well within the range 0 - 63,
I have an array of array like below with all numeric values. I want
I have an array of strings: @array I want to concatenate all strings beginning
I have an array of threads, and I want to Join them all with
You have: val array = new Array[Array[Cell]](height, width) How do you initialize all elements
Specifically, I have an array of strings called val, and want to replace all
I have a an array of observable collections and I want to display all
I have a 3D array in Python and I need to iterate over all

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.