N
N
nur20502018-06-22 10:28:26
PHP
nur2050, 2018-06-22 10:28:26

How to go through the loop so that there are no duplicate elements?

Hello, I'm scratching my head, I can not solve the problem. Help me please.
There is an array with available countries:

array(
  (int) 0 => array(
    'countries_users' => array(
      'id' => '1',
      'country_id' => '244',
      'user_id' => '6'
    )
  ),
  (int) 1 => array(
    'countries_users' => array(
      'id' => '2',
      'country_id' => '132',
      'user_id' => '6'
    )
  )
)

There are also other countries
spoiler
array(
  (int) 0 => array(
    'Country' => array(
      'id' => '132',
      'country_code' => 'MW',
      'country_name' => 'Malawi',
      'show_in_documents' => true
    )
  ),
  (int) 1 => array(
    'Country' => array(
      'id' => '152',
      'country_code' => 'NA',
      'country_name' => 'Namibia',
      'show_in_documents' => true
    )
  ),
  (int) 2 => array(
    'Country' => array(
      'id' => '200',
      'country_code' => 'ZA',
      'country_name' => 'South Africa',
      'show_in_documents' => true
    )
  ),
  (int) 3 => array(
    'Country' => array(
      'id' => '215',
      'country_code' => 'TZ',
      'country_name' => 'Tanzania, United Republic of',
      'show_in_documents' => true
    )
  ),
  (int) 4 => array(
    'Country' => array(
      'id' => '244',
      'country_code' => 'ZM',
      'country_name' => 'Zambia',
      'show_in_documents' => true
    )
  )
)

I can't bring them in and if<input type="checkbox">
countries_users['country_id'] == country['id']
are equal, then put checked. When I try, the countries start to duplicate.
Thanks for your help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question