title: How to fix this `Illegal string offset` error in php?
body: <p>I have a multidimensional array as below: </p>
  
  <pre><code>$rows[] = $row;
  </code></pre>
  
  <p>Now I want to create variable from looping this array. This is how I tried it:</p>
  
  <pre><code>foreach ($rows as $k =&gt; $value) {
    //echo '&lt;pre&gt;',print_r($value).'&lt;/pre&gt;';
    $id    = $value['news_id'];
    $title = $value['news_title'];
    echo $title; 
  }
  </code></pre>
  
  <p>But it produce an error as below:</p>
  
  <blockquote>
    <p>......  Illegal string offset 'news_id'</p>
  </blockquote>
  
  <p>This is the output of - <code>echo '&lt;pre&gt;',print_r($value).'&lt;/pre&gt;';</code> </p>
  
  <pre><code>Array
  (
      [news_id] =&gt; 1110
      [news_title] =&gt; test
      [news] =&gt; test des
  )
  1
  
  Array
  (
      [news_id] =&gt; 1109
      [news_title] =&gt; ශ්‍රී ලංකාවේ ප්‍රථම....
      [news] =&gt; දහසක් බාධක....
  )
  1
  </code></pre>
  
  <p>Can anybody tell me what is the wrong I have done? </p>
  
  <p><strong>UPDATE</strong>
  output for <code>echo '&lt;pre&gt;',print_r($rows).'&lt;/pre&gt;';</code></p>
  
  <pre><code>Array
  (
    [0] =&gt; 
    [1] =&gt; Array
        (
            [news_id] =&gt; 1110
            [news_title] =&gt; test
            [news] =&gt; test des
        )
  
    [2] =&gt; Array
        (
            [news_id] =&gt; 1109
            [news_title] =&gt; ශ්‍රී ලංකාවේ ප්‍රථම....
            [news] =&gt; දහසක් බාධක....        
        )
  
  )
  1
  </code></pre>