So, I am making a from select with the code below:
// Controller Code
$data['message_to_options'] = array(
'1' => 'username 1',
'2' => 'username 2',
);
// View Code
<?php echo form_dropdown('message_to', $message_to_options); ?>
This all works great. Except the users needs to be dynamically created not hard coded.
I have the following code from ion_auth for code igniter. This gets all the users in the system. Which Is what I want to do.
$users = $this->ion_auth->users()->result();
I just need a way to put them all together. I tried the following but it did not function correctly.
$users = $this->ion_auth->users()->result();
$data['message_to_options'] = array(
foreach($users $user){
'$user['id']' => '$user['username']',
}
);
I didn't think it would work but I figured I would give it a shot. What is the PHP AND Code igniter "legal" way of doing this?
UPDATE
So when I do run this code, I receive this error:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')'