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.159 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.158 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.157 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.156 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.155 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.154 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.153 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.152 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.151 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.150 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.149 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.148 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.147 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.146 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.145 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.144 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.143 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.142 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.141 tracks/php/exercises/grade-school/example.php
trackler-2.2.1.140 tracks/php/exercises/grade-school/example.php