Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

twoarmtom's avatar

@goldtaste It gets this error.

"class": "ErrorException", "message": "json_decode() expects parameter 1 to be string, array given",

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Right

dd($collection->first()["Attitude/Presentation: Generally positive attitude/focus on learning.  Appropriate language, behavior, attire."]);
twoarmtom's avatar

@sinnbeck I think that did it!

$q1 = $collection->avg([$professionalism_Q1]);

Gets 2.7142857142857

And I know how to clean that up.

Thank you so much!

Sinnbeck's avatar

Ok strange indeed

Totally different approach then. Writing on a mobile so it might be off

$r = [];
$c = [];
foreach ($collection as $col) {
    foreach ($col as $key => $q) {
        if (isset($r[$key]) {
            $r[$key] += $q;
            $c[$key] += 1;
       } else {
            $r[$key] = $q;
            $c[$key] = 1;
      }
   }
}

$f = [];
foreach ($r as $key => $rr) {
     $f[$key] = $rr / $c[$key];
}
Sinnbeck's avatar

Yay great to hear. Just wrote a new suggestion but that one is alot cleaner :)

1 like
Previous

Please or to participate in this conversation.