Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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_Arrays_Object - Fatal编程技术网

Php 试图创建数组但创建了一个对象

Php 试图创建数组但创建了一个对象,php,arrays,object,Php,Arrays,Object,我目前正在尝试用php创建一个数组,该数组将采用当前格式: 日历[月份][行][列],其中月份=1到6 这基本上就是我用来创建它的代码。还有很多,但我希望这足够了 function db_to_matrix($date_start, $date_end, $compliment, $workers, $worker_shifts, $shift_types) { $calendar = array(); //Sets the titles up for each months a

我目前正在尝试用php创建一个数组,该数组将采用当前格式: 日历[月份][行][列],其中月份=1到6

这基本上就是我用来创建它的代码。还有很多,但我希望这足够了

function db_to_matrix($date_start, $date_end, $compliment, $workers, $worker_shifts, $shift_types)
{
    $calendar = array();
    //Sets the titles up for each months array
    $date = clone $date_start;
    while ($date <= $date_end)
    {
        $calendar[date_format($date,'n')] = array();
        $calendar[date_format($date,'n')][0][] = "db_table";
        $calendar[date_format($date,'n')][0][] = "id";
        $calendar[date_format($date,'n')][0][] = "";
        $calendar[date_format($date,'n')][1][] = "";
        $calendar[date_format($date,'n')][1][] = "";
        $calendar[date_format($date,'n')][1][] = "";
        $calendar[date_format($date,'n')][2][] = "compliment";
        $calendar[date_format($date,'n')][2][] = "compliment_day";
        $calendar[date_format($date,'n')][2][] = "Day Comp";
        $calendar[date_format($date,'n')][3][] = "compliment";
        $calendar[date_format($date,'n')][3][] = "compliment_day_actual";
        $calendar[date_format($date,'n')][3][] = "Act Day";
        $calendar[date_format($date,'n')][4][] = "compliment";
        $calendar[date_format($date,'n')][4][] = "compliment_night";
        $calendar[date_format($date,'n')][4][] = "Night Comp";
        $calendar[date_format($date,'n')][5][] = "compliment";
        $calendar[date_format($date,'n')][5][] = "compliment_night_actual";
        $calendar[date_format($date,'n')][5][] = "Act Night";
        date_modify($date,"+1 month");
    }
}
函数db\u to\u矩阵($date\u start,$date\u end,$compaign,$workers,$worker\u shift,$shift\u types)
{
$calendar=array();
//设置每个月数组的标题
$date=克隆$date\u开始;

当($date您可能正在重新使用变量时,请尝试使用其他变量名,或在while循环之前将$calendar重置为数组


$calendar=array();

为什么要创建索引为date的数组?例如,“date”可以等于1-6…也可以是3-6或6-12…我是PHP新手,所以可能完全偏离目标,但不应该将值传递给column元素?例如
$calendar[date\u format($date,'n')][0][**3**]=“db\u table”;
@Bendy:No.
[]添加了一个新元素。因此您将获得
[0][0],[0][1],[0][2]
@abracadver-谢谢,我会保持沉默;-)我会花钱,这就是本例的原因,因为我的PHP沙盒示例工作正常……这不起作用。我将上面的代码更改为显示。相同的输出。