UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

72 lines (58 loc) 2 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://an3m1.com/" rel="nofollow">???? ????</a> </strong> on 2012-03-22 13:54:45 <br /> News and new recipes world famous in the world of Eve <hr /> <strong> <a href="www.namakusurya.com" rel="nofollow">Surya Adi Sapoetra</a> </strong> on 2010-05-30 03:39:41 <br /> i really like phpjs.. thanks... <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-01-22 08:57:02 <br /> @ Ates Goral: Great dude! <hr /> <strong> Ates Goral </strong> on 2008-01-22 05:08:02 <br /> Here's array_count_values(): <pre><code> function array_count_values(array) { // * example 1: array_count_values([ 3, 5, 3, &amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;, &amp;quot;foo&amp;quot; ]); // * returns 1: {3:2, 5:1, &amp;quot;foo&amp;quot;:2, &amp;quot;bar&amp;quot;:1} // * example 2: array_count_values({ p1: 3, p2: 5, p3: 3, p4: &amp;quot;foo&amp;quot;, p5: &amp;quot;bar&amp;quot;, p6: &amp;quot;foo&amp;quot; }); // * returns 2: {3:2, 5:1, &amp;quot;foo&amp;quot;:2, &amp;quot;bar&amp;quot;:1} // * example 3: array_count_values([ true, 4.2, 42, &amp;quot;fubar&amp;quot; ]); // * returns 3: {42:1, &amp;quot;fubar&amp;quot;:1} function countValue(value) { switch (typeof(value)) { case &amp;quot;number&amp;quot;: if (Math.floor(value) != value) { return; } case &amp;quot;string&amp;quot;: 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; } </code></pre> <hr />