예제 #1
0
파일: App.php 프로젝트: hutchike/YAWF
 protected function before()
 {
     // Put code here that should be performed by every controller
     $this->render->title = Symbol::PATH_CONFIG;
     $this->render->layout = 'purple';
     $this->render->greeting = array_rand_value(self::$greetings);
     $this->render->active_tab = array($this->path => ' class="active"');
 }
예제 #2
0
/**
 * Get a random value from an array, with the ability to skew the results.
 * Example: array_rand_weighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar.
 *
 * @param array $array
 *
 * @return mixed
 */
function array_rand_weighted(array $array)
{
    $options = [];
    foreach ($array as $option => $weight) {
        for ($i = 0; $i < $weight; ++$i) {
            $options[] = $option;
        }
    }
    return array_rand_value($options);
}