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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:51:31+00:00 2026-06-06T05:51:31+00:00

In PHP I am going to edit some entity let say a project named:

  • 0

In PHP I am going to edit some entity let say a project named: ABC this projects belongs to many countries while adding this project I used <select multiple="multiple"> and store all selected countries in a projectCountries table. Now when I start editing this project so I use same logic with a little change:

  1. populate all countries from countries table
  2. fetch all countries from projectCountries table which are associate with projectId

and I got two arrays:

Array ( 
    [0] => Array ( [countryId] => 1 [countryName] => Pakistan ) 
    [1] => Array ( [countryId] => 2 [countryName] => China ) 
) 

output from step-1

and

Array ( 
    [0] => Array ( [pcId] => 1 [countryId] => 1 [projectId] => 1 ) 
    [1] => Array ( [pcId] => 2 [countryId] => 2 [projectId] => 1 ) 
)

output from step-2

but I am confused how to show that country named China was already associated with the project (already selected in <select multiple="multiple">)

because to create <select multiple="multiple"> I used foreach loop. Now I could not guess how to compare two arrays in foreach loop so that I set selected="selected" in <option>.

  • 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-06T05:51:33+00:00Added an answer on June 6, 2026 at 5:51 am

    Iterate over all countries and check if that country exists on the projectCountries output array.

    Something like this:

    $pc_list = array();
    foreach($project_countries as $pc) {
        $pc_list[] = $pc['countryId'];  
    }
    
    foreach($countries as &$country) {
        if(in_array($country['countryId'], $pc_list)) {
            $country['selected'] = TRUE;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to be starting a fairly large PHP application this summer, on which
I'm going to pass through some values between two required/included php file,ex: mysql.php: <?php
I'm working on my first PHP project, and it's going well. I've been able
I'm having this problem with validating a document that contains some basic PHP variables.
I was going through the list of predefined Exceptions in PHP and I noticed
Everything was going great until I added AddHandler application/x-httpd-php5s .php to the .htaccess file
I was simply going through the tutorial of PHP there I found that we
I have an issue going on here. I am using PHP to get values
i am using php 5.2.4 with wampserver. everything is going fine. i have done
Can anyone spot where I might be going wrong with the following code? <?php

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.