title: Trouble making foreach loop for multi-dimensional array with StdClass Objects
body: <p>I'm learning PHP and code igniter, and am new to modern programming in general, so please be kind!</p>
  
  <p>I wrote a function to generate weekly totals of kilometers ridden on a bicycle from a mysql table. My function is generating a multi-dimensional array with Std Class objects. When I try to echo the result in my view file, I get the error : <strong>Error: Message: Object of class stdClass could not be converted to string.</strong></p>
  
  <p>I have tried instructions on how to make foreach loops for multi-dimensional arrays in about ten threads, including <a href="https://stackoverflow.com/questions/15483536/outputting-two-dimensional-array-codeigniter">this one</a>. It appears I need a nested foreach structure, however, I am not understanding how to apply these examples to my code.</p>
  
  <p>//in my controller index function</p>
  
  <pre><code>$weeknumber = array(0, 1, 2, 3, 4, 5, 6, 7);
  $bikedata['sums_for_table'] = array_map(array($this-&gt;bike_model,
    'get_weekly_sum'), $weeknumber);
  </code></pre>
  
  <p>//in my model</p>
  
  <pre><code>public function get_weekly_sum($when)
  {
      $this-&gt;db-&gt;select_sum('distance');
      $this-&gt;db-&gt;where("WEEK (date) = WEEK( current_date ) - $when AND YEAR( date) = YEAR( current_date)");
      $query = $this-&gt;db-&gt;get('bike_stats');
  
  return $query-&gt;result();
  </code></pre>
  
  <p>//in my view (trimmed for simplicity. It's actually a table.)</p>
  
  <pre><code>foreach ($sums_for_table as $sum_array):
  foreach ($sum_array as $key =&gt; $object): 
  echo $object;  
  endforeach;
  endforeach;
  </code></pre>
  
  <p>The function is working correctly in that the array returned by the functions (below, from var_dump) has the info I want in it (the numbers 63.2 etc.) but I'm having trouble understanding how to use the info in this form.</p>
  
  <pre><code>array(8) {
  [0]=&gt; array(1) { [0]=&gt; object(stdClass)#23 (1) { ["distance"]=&gt; string(4) "63.2" } }
  [1]=&gt; array(1) { [0]=&gt; object(stdClass)#24 (1) { ["distance"]=&gt; string(5) "111.9" } }
  [2]=&gt; array(1) { [0]=&gt; object(stdClass)#25 (1) { ["distance"]=&gt; string(4) "48.2" } }
  [3]=&gt; array(1) { [0]=&gt; object(stdClass)#26 (1) { ["distance"]=&gt; NULL } }
  [4]=&gt; array(1) { [0]=&gt; object(stdClass)#27 (1) { ["distance"]=&gt; string(4) "26.7" } }
  [5]=&gt; array(1) { [0]=&gt; object(stdClass)#28 (1) { ["distance"]=&gt; string(4) "42.2" } }
  [6]=&gt; array(1) { [0]=&gt; object(stdClass)#29 (1) { ["distance"]=&gt; string(4) "32.3" } }
  [7]=&gt; array(1) { [0]=&gt; object(stdClass)#30 (1) { ["distance"]=&gt; string(4) "10.9" } } }
  </code></pre>
  
  <p>My main question is how I can fix my view file code to properly output the numbers in this array. However, if I could have written my function in a different way to generate a regular associative array I would love to know that too!</p>
  
  <p>Any help would be much appreciated! </p>