PHP warning array to string conversion loop inside array key -


<?php  $student = array(      1 => array(          "firstname" => "first",          "name" => "first",          "group" => "grp01",          "score" => array(              "asp" => 86,              "php" => 79,              "java" => 72,              "html" => 96,              "javascript" => 98,              "vbnet" => 66          )      ),      2 => array(          "firstname" => "second",          "name" => "second",          "group" => "grp01",          "score" => array(              "asp" => 80,              "php" => 70,              "java" => 71,              "html" => 92,              "javascript" => 90,              "vbnet" => 78          )      ),      3 => array(          "firstname" => "third",          "name" => "third",          "group" => "grp02",          "score" => array(              "asp" => 88,              "php" => 88,              "java" => 89,              "html" => 96,              "javascript" => 98,              "vbnet" => 71          )      )  ); ?>  <?php  foreach($student $std) {     foreach($std $key => $p){         echo $std[$key];     } } ?> 

i trying print in echo each student average score right stuck got warning array string convertion can give me hint how suppose loop.

use php-functions calculate average every student, rounded 2 digits:

foreach($student $std) {      $avg = round(array_sum($std['score']) / count($std['score']), 2);     echo $std['name']. ": $avg <br />"; } 

see working: http://codepad.viper-7.com/rbincd


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -