title: Codeigniter extract Object std class and create array
body: <p>The question might be silly. But I am stucked in here. :( I am getting all of my database value as an object in controller.  </p>
  
  <p>This is how I am fetching database value:</p>
  
  <pre><code>$points = $this-&gt;CI-&gt;modelgraph-&gt;get($user_id);
  </code></pre>
  
  <p>It is getting all of the data corresponding to that user. This is my sample database table from where I am fetching data:</p>
  
  <pre><code>id  user_id    b_value    h_value    date            r_value    
  1    24        330        6.2        10.11.2014       90
  2    25        334        6.2        10.11.2014       92
  </code></pre>
  
  <p>This is static data, phpgraphlib provide in the tutorial. </p>
  
  <pre><code>$data = array("1" =&gt; .0032, "2" =&gt; .0028, "3" =&gt; .0021, "4" =&gt; .0033, 
  "5" =&gt; .0034, "6" =&gt; .0031, "7" =&gt; .0036, "8" =&gt; .0027, "9" =&gt; .0024, 
  "10" =&gt; .0021, "11" =&gt; .0026, "12" =&gt; .0024, "13" =&gt; .0036, 
  "14" =&gt; .0028, "15" =&gt; .0025);
  </code></pre>
  
  <p>I need to extract the fetched data in this manner:</p>
  
  <pre><code>$data = array("h_value" =&gt; b_value,);
  </code></pre>
  
  <p>How could achieve this? What will be the logic? Any help would be really appreciable. </p>
  
  <p>Here is my approach.. but also not complete.. What I am doing wrong?</p>
  
  <pre><code>$total=count($points);
  $i=1;
  $dataArray=array();
  while($i &lt;= $total) {
   foreach($points as $value) {
      //echo $value -&gt; h_value;
      $field = $value -&gt; h_value;
      $labels = $value -&gt; b_value;
      $dataArray[$i][$field ] = $labels;    
      $i++;
    }
  }
  </code></pre>
  
  <p>When I var_dump($dataArray); Its giving me this output:</p>
  
  <pre><code>array(11) { [1]=&gt; array(1) { ["6.6"]=&gt; string(3) "358" } [2]=&gt; array(1) { ["7.4"]=&gt; string(3) "201" } [3]=&gt; array(1) { ["6.5"]=&gt; string(3) "144" } [4]=&gt; array(1) { ["6.5"]=&gt; string(3) "112" } [5]=&gt; array(1) { ["6.2"]=&gt; string(3) "144" } [6]=&gt; array(1) { ["6.2"]=&gt; string(3) "185" } [7]=&gt; array(1) { ["7.0"]=&gt; string(3) "176" } [8]=&gt; array(1) { ["7.5"]=&gt; string(3) "234" } [9]=&gt; array(1) { ["6.5"]=&gt; string(3) "365" } [10]=&gt; array(1) { ["6.2"]=&gt; string(3) "110" } [11]=&gt; array(1) { ["4.2"]=&gt; string(3) "100" } }
  </code></pre>
  
  <p>But When I var_dump($data); Its giving this:</p>
  
  <pre><code>array(15) { [1]=&gt; float(0.0032) [2]=&gt; float(0.0028) [3]=&gt; float(0.0021) [4]=&gt; float(0.0033) [5]=&gt; float(0.0034) [6]=&gt; float(0.0031) [7]=&gt; float(0.0036) [8]=&gt; float(0.0027) [9]=&gt; float(0.0024) [10]=&gt; float(0.0021) [11]=&gt; float(0.0026) [12]=&gt; float(0.0024) [13]=&gt; float(0.0036) [14]=&gt; float(0.0028) [15]=&gt; float(0.0025) }
  </code></pre>
  
  <p>Its clearly visible I have messed up . Where is the wrong ?</p>
  
  <p>Here is the output I print_r($points); Its giving this:</p>
  
  <pre><code>Array ( [0] =&gt; stdClass Object ( [id] =&gt; 12 [user_id] =&gt; 24 [b_value] =&gt; 358 [h_value] =&gt; 6.6 [rec_date] =&gt; 2014-09-19 [rec_time] =&gt; [h_value] =&gt; 1[date_added] =&gt; 2012-09-19 16:38:05 [date_modified] =&gt; 0000-00-00 00:00:00 ) [1] ..........
  </code></pre>