This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.
21 10, 2009

array_count_values

By | 2009-11-05T15:56:11+00:00 October 21st, 2009|Categories: PHP, Ruby|Tags: , , |Comments Off on array_count_values

The array_count_values() function in PHP counts the number of instances of each value in an array. array_count_values() returns an associative array using the values of the input array as keys and their frequency in the input as values.

PHP

$a = array('a', 'b','a', 'c', 'c');
$results = array_count_values($a);
print_r($results);
/*
Array (
	[a] => 2
	[b] => 1
	[c] => 2
)
*/

To replicate this functionality in Ruby, we need to use a Hash object, since arrays in Ruby don’t use associative key/value pairs.

Ruby

a = [ "a", "b", "a", "c", "c" ];
result = list.inject({}) do |hash, key|
  hash.include?(key) ? hash[key] += 1 : hash[key] = 1;
  hash
end

p result;
# => ["a" => 2, "b" => 1, "c" => 2]