???? ???? on 2012-03-22 13:54:45
News and new recipes world famous in the world of Eve
Surya Adi Sapoetra on 2010-05-30 03:39:41
i really like phpjs.. thanks...
Kevin van Zonneveld on 2008-01-22 08:57:02
@ Ates Goral: Great dude!
Ates Goral on 2008-01-22 05:08:02
Here's array_count_values():

function array_count_values(array) {
    // *     example 1: array_count_values([ 3, 5, 3, "foo", "bar", "foo" ]);
    // *     returns 1: {3:2, 5:1, "foo":2, "bar":1}
    // *     example 2: array_count_values({ p1: 3, p2: 5, p3: 3, p4: "foo", p5: "bar", p6: "foo" });
    // *     returns 2: {3:2, 5:1, "foo":2, "bar":1}
    // *     example 3: array_count_values([ true, 4.2, 42, "fubar" ]);
    // *     returns 3: {42:1, "fubar":1}

    function countValue(value) {
        switch (typeof(value)) {
        case "number":
            if (Math.floor(value) != value) {
                return;
            }
        case "string":
            if (value in this) {
                ++this[value];
            } else {
                this[value] = 1;
            }
        }
    }
    
    var ret = new Object();
    
    if (array instanceof Array) {
        array.forEach(countValue, ret);
    } else if (array instanceof Object) {
        for (var key in array) {
            countValue.call(ret, array[key]);
        }
    }
    
    return ret;
}