Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我是否可以使用兰德(';待定';';成功';';失败';';退款';)_Php_Mysql - Fatal编程技术网

Php 我是否可以使用兰德(';待定';';成功';';失败';';退款';)

Php 我是否可以使用兰德(';待定';';成功';';失败';';退款';),php,mysql,Php,Mysql,我是否可以使用payment\u status=rand('pending'、'success'、'failed'、'returned')进行以下查询,或者有人可以帮助我了解以下查询的错误 for ($i=0;$i<100000;$i++) { $payment_status = rand('pending','success','failed','refunded'); $sql = 'INSERT INTO `aa_kkkk` (`id`, `user_id`, `bi

我是否可以使用
payment\u status=rand('pending'、'success'、'failed'、'returned')
进行以下查询,或者有人可以帮助我了解以下查询的错误

for ($i=0;$i<100000;$i++)   
{ 
$payment_status = rand('pending','success','failed','refunded');    
$sql = 'INSERT INTO `aa_kkkk` (`id`, `user_id`, `biz_id`, `filing_year`, `filing_month`, `final_return`, `consent_disclosure`, `is_third_party_designee`, `amended_month`, `earliest_date`, `latest_date`, `tax_year_end_month`, `address_change`, `form_type`, `submission_id`, `payment_status`, `transaction_id`, `active`, `xml_submitted`, `date_user_submitted`, `date_xml_sent`, `date_last_ack_attempt`, `date_acknowledged`, `created_date`, `modified_date`, `next_submission_date`, `irs_approved`, `ack_received`, `sch1_received`, `sch1_path`, `user_completed`, `consent_to_submit`, `error_code`, `error_description`, `error_type`, `modifiedby_admin`, `data_masked`, `form_pdf_path`) VALUES
(Null, ':user_id', ':biz_id', ':filing_year', "c2aaf5544415889e720f042b04551c97'.$i.'", "c9c396be60e066ae92b978c08a3fca0a'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "0", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'", "32b20aa703b1128d448321b83fe57d70'.$i.'",  "84843320140520033138'.$i.'", ':payment_status', "", ':transaction_id', ':active', "2014-02-21 10:31:35", "2014-02-21 03:31:42", "2014-02-21 03:32:00", "2014-02-21 03:32:00", "2014-02-21 03:11:15", "2014-04-18 11:12:39", NULL, ':irs_approved', ':ack_received', ':sch1_received', "84843320140520033138.pdf'.$i.'", 1, 1, "", "", "", 0, 0, "pf2290_1_84843320140520033138.pdf'.$i.'")';
$i=0;$i的

警告:rand()只需要2个参数,给定4个

文件:

所以,不,你不能。不是那样的

这将有助于:

$values = array('pending','success','failed','refunded');
$payment_status = $values[rand(0, sizeof($values)-1)];
或者使用(必须热爱PHP…一个适用于一切的函数…):

为了好玩,您还可以发挥创意并使用:

尽管这远不如上面的两个选项有效,因为它将首先洗牌数组,然后返回数组中的第一个元素,而不是从列表中选择一个随机元素并返回该元素

$rand = $array[array_rand($array = ['pending','success','failed','refunded'])];
或:


或者…

您可以使用以下

$k = array_rand($array);
$v = $array[$k];
见文件

享受:)

你也可以这样做

$input = array('pending','success','failed','refunded'); 
echo $input[array_rand($input)];

我更喜欢这种方法,因为通过使用它,您不必指定数组的大小。在某些情况下可能是未知的。

int rand(int$min,int$max)
不,不,你不能。我建议编辑问题以更好地反映您想要做的事情,而不是就您选择的(有缺陷的)解决方案寻求帮助。此外,这个问题中绝对没有mysql-如何使用
$payment\u status
与“问题”无关。
我更喜欢这种方法,因为使用这种方法,您不必指定数组的大小。
->这不就是问题所在吗?:-)@RobIII我也更喜欢代码行数较少的代码。就像你说的“PHP…一个万能的函数…”那么为什么不将一个函数与所有函数一起使用,而不是混合使用多个内置函数呢?来自其他平台,只是偶尔使用PHP,我倾向于远离“模糊”函数,如array_rand(和所有其他函数)(有时)很有用,但在任何其他语言中都找不到”-功能)。“那只是我的习惯……”罗比同意。在这种情况下,我通常使用您建议的sizeof()开发自己的array_rand()函数。谢谢你的意见。
$rand = $array[array_rand($array = ['pending','success','failed','refunded'])];
$array = ['pending','success','failed','refunded'];
$rand  = $array[rand(0, count($array)-1)];
$k = array_rand($array);
$v = $array[$k];
$input = array('pending','success','failed','refunded'); 
echo $input[array_rand($input)];