本文整理汇总了PHP中array_rand函数的典型用法代码示例。如果您正苦于以下问题:PHP array_rand函数的具体用法?PHP array_rand怎么用?PHP array_rand使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_rand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startSession
/**
* Sets the time against which the session is measured. This function also
* sets the cash_session_id internally as a mechanism for tracking analytics
* against a consistent id, regardless of PHP session id.
*
* @return boolean
*/
protected function startSession()
{
// begin PHP session
if (!defined('STDIN')) {
// no session for CLI, suckers
@session_cache_limiter('nocache');
$session_length = 3600;
@ini_set("session.gc_maxlifetime", $session_length);
@session_start();
}
$this->cash_session_timeout = ini_get("session.gc_maxlifetime");
if (!isset($_SESSION['cash_session_id'])) {
$modifier_array = array('deedee', 'johnny', 'joey', 'tommy', 'marky');
$_SESSION['cash_session_id'] = $modifier_array[array_rand($modifier_array)] . '_' . rand(1000, 9999) . substr((string) time(), 4);
}
if (isset($_SESSION['cash_last_request_time'])) {
if ($_SESSION['cash_last_request_time'] + $this->cash_session_timeout < time()) {
$this->resetSession();
}
}
$_SESSION['cash_last_request_time'] = time();
if (!isset($GLOBALS['cash_script_store'])) {
$GLOBALS['cash_script_store'] = array();
}
return true;
}
示例2: createCode
function createCode($len = 4)
{
$width = 100;
$height = 50;
$size = 22;
//字体大小
$font = ROOT_PATH . '/static/font/arial.ttf';
//字体
$img = imagecreatetruecolor($width, $height);
//创建画布
$bgimg = imagecreatefromjpeg(ROOT_PATH . '/static/background/' . rand(1, 5) . '.jpg');
//生成背景图片
$bg_x = rand(0, 100);
//随机招贴画布起始X轴坐标
$bg_y = rand(0, 50);
//随机招贴画布起始Y轴坐标
imagecopy($img, $bgimg, 0, 0, $bg_x, $bg_y, $bg_x + $width, $bg_y + $height);
//把背景图片$bging粘贴的画布上
$str = $this->creaStr($len);
//字符串
for ($i = 0, $j = 5; $i < 4; $i++) {
$array = array(-1, 1);
$p = array_rand($array);
$an = $array[$p] * mt_rand(1, 10);
//扭曲角度
imagettftext($img, $size, $an, $j + 5, 34, imagecolorallocate($img, rand(0, 100), rand(0, 100), rand(0, 100)), $font, $str[$i]);
//生成验证字符窜
$j += 20;
}
cookie('captchacode', strtolower($str));
header('Content-type:image/png');
imagepng($img);
imagedestroy($img);
}
示例3: random_element
function random_element($array)
{
if (!is_array($array)) {
return $array;
}
return $array[array_rand($array)];
}
示例4: taxonomy
/**
*
* Assigns random terms to all posts in a taxonomy.
*
* By default all objects of the 'post' post type will be randomized, use the
* --post_type flag to target pages or a custom post type. Use the --include
* and --exclude flags to filter or ignore specific object IDs and the --before
* and --after flags to specify a date range. Also, optionally pass --terms as
* a list of terms you want to use for the randomization. If terms exist in the
* target taxonomy, those terms will be used. If not, a string of 6 words
* generated randomly will be used for the randomization.
*
* ## Options
*
* <taxonomy>
* : The taxonomy that should get randomized
*
* ## Exmples
*
* wp randomize category
*
* @synopsis <taxonomy> [--include=<bar>] [--exclude=<foo>] [--post_type=<foo>]
* [--before=<bar>] [--after=<date>] [--terms=<terms>]
*
**/
public function taxonomy($args, $assoc_args)
{
$taxonomy = $args[0];
$get_posts = $this->get_specified_posts($assoc_args);
$message = $get_posts['message'];
$posts = $get_posts['posts'];
$args = $get_posts['args'];
$preamble = "Will assign random {$taxonomy} terms";
print_r("{$preamble} {$message}.\n");
if (isset($assoc_args['terms'])) {
$terms = explode(',', $assoc_args['terms']);
\WP_CLI::log('Using terms ' . $assoc_args['terms']);
} else {
\WP_CLI::log('Gathering and processing random terms.');
$terms = $this->get_random_terms();
\WP_CLI::log('No term list given, using random terms.');
}
foreach ($posts as $p) {
$index = array_rand($terms);
$term = $terms[$index];
\WP_CLI::log("Assigning {$term} to taxonomy {$taxonomy} for {$p->post_type} {$p->ID}");
if (!term_exists($term, $taxonomy)) {
wp_insert_term($term, $taxonomy);
}
wp_set_object_terms($p->ID, $term, $taxonomy, $append = false);
}
}
示例5: get_linked_tags
/**
* 获得商品tag所关联的其他应用的列表
*
* @param array $attr
*
* @return void
*/
function get_linked_tags($tag_data)
{
//取所有应用列表
$app_list = uc_call("uc_app_ls");
if ($app_list == '') {
return '';
}
foreach ($app_list as $app_key => $app_data) {
if ($app_data['appid'] == UC_APPID) {
unset($app_list[$app_key]);
continue;
}
$get_tag_array[$app_data['appid']] = '5';
$app_array[$app_data['appid']]['name'] = $app_data['name'];
$app_array[$app_data['appid']]['type'] = $app_data['type'];
$app_array[$app_data['appid']]['url'] = $app_data['url'];
$app_array[$app_data['appid']]['tagtemplates'] = $app_data['tagtemplates'];
}
$tag_rand_key = array_rand($tag_data);
$get_tag_data = uc_call("uc_tag_get", array($tag_data[$tag_rand_key], $get_tag_array));
foreach ($get_tag_data as $appid => $tag_data_array) {
$templates = $app_array[$appid]['tagtemplates']['template'];
if (!empty($templates) && !empty($tag_data_array['data'])) {
foreach ($tag_data_array['data'] as $tag_data) {
$show_data = $templates;
foreach ($tag_data as $tag_key => $data) {
$show_data = str_replace('{' . $tag_key . '}', $data, $show_data);
}
$app_array[$appid]['data'][] = $show_data;
}
}
}
return $app_array;
}
示例6: lrss_init
function lrss_init()
{
if (is_admin()) {
return NULL;
}
if (!function_exists('is_plugin_active_for_network')) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
if (is_multisite() && is_plugin_active_for_network(FB_WM_BASENAME)) {
$value = get_site_option(FB_WM_TEXTDOMAIN);
} else {
$value = get_option(FB_WM_TEXTDOMAIN);
}
// set for additional option. not save in db
if (!isset($value['support'])) {
$value['support'] = 0;
}
// break, if option is false
if (0 === $value['support']) {
return NULL;
}
//Create a simple array of all the places the link could potentially drop
$actions = array('wp_meta', 'get_header', 'get_sidebar', 'loop_end', 'wp_footer', 'wp_head', 'wm_footer');
$actions = array('wm_footer');
//Choose a random number within the limits of the array
$nd = array_rand($actions);
//Set the variable $spot to the random array number and get the value
$spot = $actions[$nd];
//Add the link to the random spot on the site (please note it adds nothing if the visitor is not google)
add_action($spot, 'lrss_updatefunction');
}
示例7: render
/**
* Outputs the Captcha image.
*
* @param boolean html output
* @return mixed
*/
public function render($html)
{
// Creates a black image to start from
$this->image_create(Captcha::$config['background']);
// Add random white/gray arcs, amount depends on complexity setting
$count = (Captcha::$config['width'] + Captcha::$config['height']) / 2;
$count = $count / 5 * min(10, Captcha::$config['complexity']);
for ($i = 0; $i < $count; $i++) {
imagesetthickness($this->image, mt_rand(1, 2));
$color = imagecolorallocatealpha($this->image, 255, 255, 255, mt_rand(0, 120));
imagearc($this->image, mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(0, 360), mt_rand(0, 360), $color);
}
// Use different fonts if available
$font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
// Draw the character's white shadows
$size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / strlen($this->response));
$angle = mt_rand(-15 + strlen($this->response), 15 - strlen($this->response));
$x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * strlen($this->response));
$y = (Captcha::$config['height'] - $size) / 2 + $size;
$color = imagecolorallocate($this->image, 255, 255, 255);
imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response);
// Add more shadows for lower complexities
Captcha::$config['complexity'] < 10 and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font, $this->response);
Captcha::$config['complexity'] < 8 and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font, $this->response);
Captcha::$config['complexity'] < 6 and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font, $this->response);
Captcha::$config['complexity'] < 4 and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font, $this->response);
Captcha::$config['complexity'] < 2 and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font, $this->response);
// Finally draw the foreground characters
$color = imagecolorallocate($this->image, 0, 0, 0);
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response);
// Output
return $this->image_render($html);
}
示例8: connect
public static function connect($type = 'master')
{
$config = self::$config;
if ($type == 'master') {
$dbinfo = $config[0];
//第一个数组为主库
} else {
//若有更多db配置
if (isset($config[0])) {
$tmpconfig = $config;
array_shift($tmpconfig);
$dbinfo = $tmpconfig[array_rand($tmpconfig)];
} else {
$dbinfo = $config[0];
//还是用主库
}
}
//连接池key值
$linkkey = md5(serialize($dbinfo));
if (isset(self::$links[$linkkey])) {
self::$curlink = self::$links[$linkkey];
return true;
}
self::$dbinfo = $dbinfo;
$curlink = new \mysqli($dbinfo['host'], $dbinfo['user'], $dbinfo['pwd'], $dbinfo['dbname']);
if ($curlink->connect_error) {
self::halt($curlink->connect_error, $curlink->connect_errno, 'connect error');
} else {
self::$curlink = self::$links[$linkkey] = $curlink;
$sql = 'SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary';
$curlink->query($sql);
}
}
示例9: __generateNormalNameAction
/**
* @param string $gender
*/
private function __generateNormalNameAction($gender = 'all')
{
$nation = empty($this->request->getPost("nation")) ? '' : $this->request->getPost("nation");
// 姓名データ生成
$model = new MasterNormalNames();
$names = $model->findNormalNames(1, $nation, $gender);
$this->view->setVar('normalNames', $names);
// 処理の都合上ここで出自(parent)のデータ生成
$model2 = new MasterNations();
$parent = array('father' => 'UNKNOWN', 'mother' => 'UNKNOWN');
if ($nation != 'all') {
$parentRecord = $model2->findFirst("nation_id = '{$nation}'");
$parent = array('father' => $parentRecord->body_ja, 'mother' => $parentRecord->body_ja);
} else {
foreach ($names as $name) {
// 0 or 1
$hash = array(0, 1);
$keys = array_rand($hash, 2);
shuffle($keys);
$fatherRecord = $model2->findFirst("nation_id = '" . $name['nation'][$keys[0]] . "'");
$motherRecord = $model2->findFirst("nation_id = '" . $name['nation'][$keys[1]] . "'");
$parent = array('father' => $fatherRecord->body_ja, 'mother' => $motherRecord->body_ja);
}
}
$this->view->setVar('parent', $parent);
}
示例10: run
public function run()
{
$choices = array('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely', 'You may rely on it', 'As I see it, yes', 'Most likely', 'More than likely', 'Outlook good', 'Yes', 'No', 'Lol no', 'Signs point to, yes', 'Reply hazy, try again', 'Ask again later', 'I Better not tell you now', 'I Cannot predict now', 'Concentrate and ask again', 'Don\'t count on it', 'My reply is no', 'My sources say no', 'Outlook not so good', 'Very doubtful');
$this->message->reply($choices[array_rand($choices)]);
// Mark this as garbage
$this->isGarbage();
}
示例11: createAction
/**
* 创建便签
*/
public function createAction()
{
$post = $this->_request->getPost();
$orgId = $this->_user->orgId;
$uniqueId = $this->_user->uniqueId;
/* @var $daoNote Dao_Td_Note_Note */
$daoNote = $this->getDao('Dao_Td_Note_Note');
$noteId = Dao_Td_Note_Note::getNoteId();
$color = !empty($post['color']) ? $post['color'] : $this->_randColors[array_rand($this->_randColors)];
$createTime = time();
$params = array('orgid' => $orgId, 'uniqueid' => $uniqueId, 'noteid' => $noteId, 'content' => $post['content'], 'color' => (int) base_convert($color, 16, 10), 'createtime' => $createTime);
if (!empty($post['tid'])) {
$params['tuduid'] = $post['tid'];
}
$ret = $daoNote->createNote($params);
// 标记图度有便签
if ($ret && !empty($post['tid'])) {
/* @var $daoTudu Dao_Td_Tudu_Tudu */
$daoTudu = $this->getDao('Dao_Td_Tudu_Tudu');
$tudu = $daoTudu->getTuduById($uniqueId, $post['tid']);
if (null !== $tudu) {
$daoTudu->updateTuduUser($post['tid'], $uniqueId, array('mark' => 1));
}
}
return $this->json(true, '操作成功', array('noteid' => $noteId, 'updatetime' => date('Y.m.d H:i', $createTime)));
}
示例12: choixOrdi
function choixOrdi()
{
$tableau = array("pierre", "feuille", "ciseaux");
$choixRandom = $tableau[array_rand($tableau)];
echo $choixRandom . "\n";
return $choixRandom;
}
示例13: getRandomAliveUnit
public function getRandomAliveUnit()
{
$aliveUnits = array_filter($this->getUnits(), function ($unit) {
return $unit->isAlive();
});
return $aliveUnits[array_rand($aliveUnits)];
}
示例14: ajax_refresh_captcha
public function ajax_refresh_captcha()
{
$length = 5;
$charset = 'abcdefghijklmnpqrstuvwxyz123456789';
$phrase = '';
$chars = str_split($charset);
for ($i = 0; $i < $length; $i++) {
$phrase .= $chars[array_rand($chars)];
}
$resp = $resp2 = array();
$resp['txt_color_st'] = isset($_POST['txt_color_st']) ? Uiform_Form_Helper::sanitizeInput($_POST['txt_color_st']) : '';
$resp['txt_color'] = isset($_POST['txt_color']) ? Uiform_Form_Helper::sanitizeInput($_POST['txt_color']) : '';
$resp['background_st'] = isset($_POST['background_st']) ? Uiform_Form_Helper::sanitizeInput($_POST['background_st']) : '';
$resp['background_color'] = isset($_POST['txt_color_st']) ? Uiform_Form_Helper::sanitizeInput($_POST['background_color']) : '';
$resp['distortion'] = isset($_POST['distortion']) ? Uiform_Form_Helper::sanitizeInput($_POST['distortion']) : '';
$resp['behind_lines_st'] = isset($_POST['behind_lines_st']) ? Uiform_Form_Helper::sanitizeInput($_POST['behind_lines_st']) : '';
$resp['behind_lines'] = isset($_POST['behind_lines']) ? Uiform_Form_Helper::sanitizeInput($_POST['behind_lines']) : '';
$resp['front_lines_st'] = isset($_POST['front_lines_st']) ? Uiform_Form_Helper::sanitizeInput($_POST['front_lines_st']) : '';
$resp['front_lines'] = isset($_POST['front_lines']) ? Uiform_Form_Helper::sanitizeInput($_POST['front_lines']) : '';
$resp['ca_txt_gen'] = $phrase;
$captcha_options = Uiform_Form_Helper::base64url_encode(json_encode($resp));
$resp2 = array();
$resp2['rkver'] = $captcha_options;
//return data to ajax callback
header('Content-Type: application/json');
echo json_encode($resp2);
wp_die();
}
示例15: getIndex
public function getIndex($location = '')
{
$loading_arr = Config::get('loading');
$loading = $loading_arr[array_rand($loading_arr)];
View::share('location', $location);
$this->layout->content = View::make('index', compact('loading'));
}