Array to string conversion error in Codeigniter
<p>I'm trying to display an average result from the database to the view but I keep getting this error: </p>

<p>A PHP Error was encountered</p>

<p>Severity: Notice</p>

<p>Message: Array to string conversion</p>

<p>Filename: views/resultview.php</p>

<p>Line Number: 38</p>

<p>Here is the code from the Controller:</p>

<pre><code>$average['avg'] = $this-&gt;quiz-&gt;getAverage($quizid);

$this-&gt;load-&gt;view('resultview',array('quiz' =&gt; $quiz,
                                     'score' =&gt; $score, 
                                     'average_score' =&gt; $average));
</code></pre>

<p>The function from the model is the following:</p>

<pre><code>   function getAverage($quiz) 
    {
    //get percentage from the database 

    $this-&gt;db-&gt;select_avg('score');
    $this-&gt;db-&gt;where('id', $quiz);
    $res = $this-&gt;db-&gt;get('userScoreQuiz');

    if ($res-&gt;num_rows() != 1) {
        // there should only be one row - anything else is an error
        return false;
    }
    return $res-&gt;result_array();
}
</code></pre>

<p>and the code from the view it is:</p>

<pre><code>&lt;h4&gt; Avg. score on all previous attempts: &lt;?php echo $average_score['avg'] ?&gt;   %&lt;/h4&gt; 
</code></pre>

<p>I can't seam to find out why it does this.</p>

<p>Thank you for your help guys.</p>