title: CodeIgniter: Sending array from model to viewer
body: <p>How do I send an array from the model- to the view-file? </p>
  
  <p>Background:
  I have a form where name can be put into (View-file). Then I pass this info on to my controller-file, which check if there is information added to the form. If not error message shows up and tells the user that names must be added. If names has been added to the form the controller then pass the info over to the model which check the database if any of the names already exists in the database. If some or all names already exists in the database they are passed on to an <strong>array</strong>. If the name is NOT added to the database the model-file adds them to the database. </p>
  
  <p>I want to get the array of the names which already are in the database and output these for the user. So this is why I need the array with the names already in the database.</p>
  
  <pre><code>User add:
  Mark
  Sophie
  Dan
  Josh
  
  Already in database:
  Mark 
  Dan
  
  Array then contains (should be output to the user):
  Mark
  Dan
  </code></pre>
  
  <p>One solution I thought was possible was to add a return statement to the function in the model-file. And retrive the array like this:</p>
  
  <pre><code>$data['nameArray'] = $this-&gt;model_name-&gt;add_name();
  </code></pre>
  
  <p>But this won't work, because if the user have missed to add information to the form the else statement will be shown and the $data['nameArray'] will not be defined. Which lead to the error message "Undefined variable", when trying to output it in the view-file.</p>