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.180 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.179 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.178 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.177 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.176 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.175 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.174 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.173 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.172 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.171 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.170 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.169 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.167 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.166 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.165 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.164 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.163 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.162 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.161 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.160 tracks/php/exercises/grade-school/example.php