English 中文(简体)
PHP 如何从阵列中获得随机价值
原标题:PHP How to get a random value from array

i)

$row4 = mysql_fetch_array($sql_res);

谁能帮助我如何获得<代码>$row4 [ response ]的随机值?

the $row4 does not have constant values...
but for now $row4 contains

Array ( [0] => 3 [id] => 3 [1] => where is dryad [react] => where is dryad [2] => Dryad is found in the farthest part of the Dark wilderness. [response] => Dryad is found in the farthest part of the Dark wilderness. [3] => [review] => ) 1
问题回答

既然你现在的法典是正确的,你只能接回一排。 这一增长只是含有你的实地价值观。 如果你确实试图从这一单一渠道获得随机的实地价值,你将使用:

$randomKey = array_rand($row4,1);

如果你打算要求从你的询问中随机浏览,你可以采取两种方式之一:

(1) 使用<条码>条码_rand,以 gr取一条任意的行文,并放置在<条码>上 Row:

while($row = mysql_fetch_array($sql_res)) $rows[] = $row;
$randomRow = array_rand($rows);

2) 在您的询问中,你可以具体指出,只剩下1个断层,而不是每个结果:

www.un.org/Depts/DGACM/index_french.htm LiMIT 1;





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签