Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
Last active December 11, 2015 05:29
Show Gist options
  • Select an option

  • Save jehoshua02/4552735 to your computer and use it in GitHub Desktop.

Select an option

Save jehoshua02/4552735 to your computer and use it in GitHub Desktop.
Counting in ruby and php.
<?php
function countBy($x = 1, $to = 100)
{
return range(0, $to, $x);
}
function countOccuranceOf($value, $array)
{
$counts = array_count_values($array);
return (array_key_exists($value, $counts)) ? $counts[$value] : 0;
}
def count_by(x = 1, to = 100)
(0..to).step(x)
end
def count_occurance_of(value, array)
array.count(value)
end
@jehoshua02
Copy link
Copy Markdown
Author

Okay, so I guess PHP has some functions to do this. I was originally thinking I'd need loops. But the PHP manual shows some functions I must have missed the first time I read through it (from cover to cover). Still, I find the ruby syntax to be superior, and -- still -- more compact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment