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"'); }
/** * 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); }