Access array keys on a for each loop

Hello forums
How do I access array keys on a for each loop?

$r = array('1'=> 'user1', '2' => 'user2', '3' => 'user3');

echo '<select>';

foreach ($r as $value){
   echo '<option value="">'.$value.'</option>';


echo '</select>';

I want the array index on the option value. Something like :
<option value=“1”>user1</option>
<option value=“2”>user2</option>
<option value=“3”>user3</option>


NVM here’s what I have

it should be:

foreach ($r as $key => $value)

function getUserSelect($id){

$r = array('1'=> 'Administrator', '2' => 'Webmaster', '3' => 'Accounting','4'=>'User');
foreach ($r as $key => $value) {

	if ($key == $id){
	$s ='selected="selected"';
	$s ='';

$t .=  '<option value="'.$key.'" '.$s.'>'.$value.'</option>';

return '<select>'.$t.'</select>';

return $t;


echo  getUserSelect(4);