Sha256: cebe42405c89b2df77c1eb9dcafb3e343594041df80219aec4d5fa6f35603200

Contents?: true

Size: 777 Bytes

Versions: 276

Compression:

Stored size: 777 Bytes

Contents

<?php

class School
{
    private $database = array() ;

    public function numberOfStudents()
    {
        return (count($this->database, COUNT_RECURSIVE) - count($this->database)) ;
    }

    public function add($student, $grade)
    {
        $this->database[$grade][] = $student ;
    }

    public function grade($grade)
    {
        return (array_key_exists($grade, $this->database) ? $this->database[$grade] : array()) ;
    }

    public function studentsByGradeAlphabetical()
    {
        $tmp = $this->database ;
        ksort($tmp) ;

        foreach ($tmp as $grade => $students) {
            asort($students) ;
            foreach ($students as $student) {
                $res [ $grade ][] = $student ;
            }
        }
        return $res ;
    }
}

Version data entries

276 entries across 276 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.97 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.96 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.95 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.94 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.93 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.92 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.91 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.90 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.89 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.88 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.87 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.86 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.85 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.84 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.83 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.82 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.81 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.80 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.79 tracks/php/exercises/grade-school/example.php