我使用PHP 5.5,但我的工作知识非常有限 - 我只是在学习。我不能让我的代码工作。
我有一个包含20个值的数组EP。我为网站的每个新访问者洗牌这些值,因此它们总是按随机顺序排列。
$EP = array(30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220);
$EP = shuffle($EP);
我有一组其他数组
$P[] = [81,102,74,157,93,106,0,0]
$P[] = [71,102,76,157,93,106,0,0]
$P[] = [91,102,74,7,93,106,0,0]
$P[] = [56,100,89,15,93,106,0,0]
总共20个
我需要的是EP阵列的每个元素都使用了一次,最后添加了0,所以它看起来像这样:
$P[] = [81,102,74,157,93,106,0,0,$EP(0),0];]
$P[] = [71,102,76,157,93,106,0,0,$EP(1),0];]
$P[] = [91,102,74,7,93,106,0,0,$EP(2),0];]
$P[] = [56,100,89,15,93,106,0,0,$EP(3),0];]
以便使用EP的所有20个数组元素。
我的代码有效,直到我添加EP数组并在我的其他数组中添加了EP(1)等。:
<?php
$Return = array();
$P = array();
$S = array();
$F = array();
$EP = array(30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220);
$EP = shuffle($EP);
//ts1
$P[] = [81,102,74,157,93,106,$EP(0),0];
$S[] = [this series is not important fo rmy question];
//ts2
$P[] = [184,0,0,0,0,0,0,105,$EP(1),0];
$S[] = [..];
//ts3
$P[] = [0,0,0,0,0,$EP(2),0];
$S[] = [..];
//and so on till time series ts20
//for loop below worked until I added the EP series, so it must have something to do with how I call the EP elements from the array.
for($i=0; $i<count($P); $i++)
{
$Return[] = $P[$i];
$Return[] = $S[$i];
$Return[] = $F[$i];
}
die(json_encode($Return));
?>