PHP警告数组到数组键内的字符串转换循环

<?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 as $std) {
    foreach($std as $key => $p){
        echo $std[$key];
    } } ?>

i am trying to print in echo each student with they average score but right now i am stuck i got a warning about array to string convertion can someone give me some hint how i am suppose to do my loop.

Use PHP-functions to calculate the average for every student, rounded to two digits:

foreach($student as $std) {

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

see it working: http://codepad.viper-7.com/RBINCd

You are iterating the wrong array, once inside each student you must iterate over the "score", if not you were trying to convert the score array to a string:

foreach($student as $std) {
    foreach($std["score"] as $language => $score) {
        echo $score;
    }
}

The error you are getting comes when you try to echo the "score" portion of the array. As it is itself an array it cannot be echo'd out in this way. You will need another loop to add up the scores, then get the average outside of it.

Something along the lines of:

foreach($student as $std) {
    foreach($std as $key => $p){

        if ( $key === 'score'){

            $avg = 0;

            foreach( $p as $score){
              $avg += $score;
            }

            $avg = ($avg/size_of($p));
         }

    } 
}