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.

array_fill_keys

The array_fill_keys() function in PHP allows you to populate the values of an array while specifying its keys.

PHP

$keys = array('write', 'debug', 'execute');
$result = array_fill_keys($keys, 'code');
var_export($result);
// => array('write' => 'code', 'debug' => 'code', 'execute' => 'code')

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

keys = ['write', 'debug', 'execute']
result = keys.inject({}) do |hash, key| 
  hash[key] = 'code'
  hash 
end
p result
# => {"write"=>"code", "debug"=>"code", "execute"=>"code"}
By | 2010-11-11T13:02:39+00:00 November 11th, 2010|Categories: PHP, Ruby|Tags: , , , |1 Comment

About the Author:

One Comment

  1. Arsenic July 1, 2011 at 3:40 am

    Why the bleep is this so complicated?
    Try this:

    result = {}
    keys.each{|k| result[k] = ‘code’}

Comments are closed.