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_rand

The array_rand() function in PHP randomly selects one or more elements from an array.

PHP

$users = array('john', 'jane', 'tim', 'alex');
$lucky_winner = array_rand($users);
echo $lucky_winner;
// alex 

Ruby

users = [ 'john', 'jane', 'tim', 'alex' ];
lucky_winner = users[rand(users.length)];
puts lucky_winner;
# => alex 
By | 2010-02-16T15:18:42+00:00 February 16th, 2010|Categories: PHP, Ruby|Tags: , , , , , |1 Comment

About the Author:

One Comment

  1. Rudie January 17, 2011 at 1:31 am

    Actually, this is just not true.

    array_rand returns a random KEY of the givven array. So to get the value, you’d use:

    $random_value = $users[array_rand($users)];

    Might look strange, but is very smart, because like this you can have both the key and the value. Sort of like in ruby =) except in php in works for assoc arrays as well. SPL ftw!

Comments are closed.