简体   繁体   English

Php不支持的操作数类型

[英]Php unsupported operand type

I got this: 我懂了:

$newcw = array_rand( range( 1, 52 ), 15 ) ;
shuffle($newcw);
$year = date("Y");
$time = mktime(0,0,0,1,1,$year) + ($newcw * 7 * 24 * 60 * 60);
$time = $time - ((date('N', $time) - 1) * 24 * 60 * 60);

$startWeek = date('D d-M-Y', $time);
$endWeek = date('D d-M-Y', $time + (6 * 24 * 60 * 60));

So basically I get a random integer which stands for calender week. 所以基本上我得到一个随机整数代表压延周。

I calculate the starting day (monday) and ending day(sunday) of that calender week. 我计算该日历周的开始日(星期一)和结束日(星期日)。

But I get following error: 但我得到以下错误:

Fatal error: Unsupported operand types in 88 致命错误:88中不支持的操作数类型

line 88 would be this line: 第88行是这一行:

$time = mktime(0,0,0,1,1,$year) + ($newcw * 7 * 24 * 60 * 60);

EDIT: I want a random integer which shall not repeats itself, that it why I am trying this method. 编辑:我想要一个随机整数,它不会重复,这就是我尝试这种方法的原因。

If you just want a single value, use regular rand function: 如果您只想要一个值,请使用常规的rand函数:

//$newcw = array_rand( range( 1, 52 ), 15 ) ;
//shuffle($newcw);

$newcw = rand(1,52);

http://php.net/manual/en/function.rand.php http://php.net/manual/en/function.rand.php

If however you actually need to use the other 14 values somewhere later in the script, you can just select the 1st element in the suffled array for this calculation: 但是,如果您实际上需要在脚本中稍后的某处使用其他14个值,则只需在此计算的已填充数组中选择第一个元素:

$newcw = array_rand( range( 1, 52 ), 15 ) ;
shuffle($newcw);
$year = date("Y");
$time = mktime(0,0,0,1,1,$year) + ($newcw[0] * 7 * 24 * 60 * 60); //<-- note [0]

Then use the other values as required, by incrementing the key each time, eg: 然后根据需要使用其他值,每次都增加键,例如:

some_func($newcw[1]); 

$val = $newcs[2] + 100; 
//....
another_func($newcw[14];

$newcw是数组,你尝试使用整数$newcw数组,这就是你在这一行得到错误的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM