-3

I've got 2 arrays with the same $key. So arrays are: $users and $new.

$users['user_id']=['user_name'];
$new['user_id']=['user_color'];

How can I foreach them that I could get something like this:

foreach (bla bla bla){
    echo '<option color="'.$new['user_color'].'" value="'.$key.'">'.$user['value'].'</option>';
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Albance
  • 169
  • 1
  • 2
  • 11

1 Answers1

3

You can use a regular foreach loop which treats one array as an associative array, and just get the value corresponding to the key from the other:

foreach ($users as $key => $value) {
    echo '<option color="' . $new[$key] . '"value="' . $key . '">'. $value . '</option>';
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350