select('cp')->get()->toArray(); //dd($reld); for($i=19;$i float(170.6) } [1]=> obj..." /> select('cp')->get()->toArray(); //dd($reld); for($i=19;$i float(170.6) } [1]=> obj..."> select('cp')->get()->toArray(); //dd($reld); for($i=19;$i float(170.6) } [1]=> obj..." />

Array getting converted to stdClass on addition

Refresh

2 weeks ago

Views

26 time

0

I have two arrays which I want to add under certain conditions which is provided by for loop. But I get the error, "Object of class stdClass could not be converted to number." on the last line.

$reld=DB::table('jp')->select('cp')->get()->toArray();
     //dd($reld);
     for($i=19;$i<=5957;$i++)
     {
       $l=$i-19;
       $fdp[$l]=0;
       $tdp[$l]=0;
       $l=$i-19;
       $cup[$l]=$reld[$i];
       for($j=0;$j<=4;$j++)
       {
         $m=$i-$j;
         $fdp[$l]=$fdp[$l] + $reld[$m]; 

output of var_dump($reld):

array(5958) { [0]=> object(stdClass)#217 (1) { ["cp"]=> float(170.6) } [1]=> object(stdClass)#219 (1) { ["cp"]=> float(168.1) } [2]=> object(stdClass)#220 (1) { ["cp"]=> float(166) } [3]=> object(stdClass)#221 (1) { ["cp"]=> float(160.65) } [4]=> object(stdClass)#222 (1) { ["cp"]=> float(158.38) } [5]=> object(stdClass)#223 (1) { ["cp"]=> float(151.18) } [6]=> object(stdClass)#224 (1) { ["cp"]=> float(143.68) } [7]=> object(stdClass)#225 (1) { ["cp"]=> float(147.63) } [8]=>                                                                                

0 answers