Getting count() of class static array

Posted by xylar on Stack Overflow See other posts from Stack Overflow or by xylar
Published on 2012-12-17T22:53:10Z Indexed on 2012/12/17 23:03 UTC
Read the original article Hit count: 196

Filed under:
|
|

Is it possible to get the count of a class defined static array? For example:

class Model_Example
{

    const VALUE_1 = 1;
    const VALUE_2 = 2;
    const VALUE_3 = 3;

    public static $value_array = array(
        self::VALUE_1 => 'boing',
        self::VALUE_2 => 'boingboing',
        self::VALUE_3 => 'boingboingboing',
    );

    public function countit()
    {
        // count number
        $total = count(self::$value_array );
        echo ': ';
        die($total);
    }
}

At the moment calling the countit() method returns :

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays