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

PHP-将数据数组化为变量

PHP-将数据数组化为变量,php,arrays,variables,Php,Arrays,Variables,我有以下数组输出: [0] => Array ( [date] => 2014-04-02 [0] => 2014-04-02 [shiftName] => Long Day [1] => Long Day ) [1] => Array ( [date] => 2014-04-03 [0] => 2014-04-03

我有以下数组输出:

[0] => Array
    (
        [date] => 2014-04-02
        [0] => 2014-04-02
        [shiftName] => Long Day
        [1] => Long Day
    )

[1] => Array
    (
        [date] => 2014-04-03
        [0] => 2014-04-03
        [shiftName] => Long Day
        [1] => Long Day
    )

[2] => Array
    (
        [date] => 2014-04-04
        [0] => 2014-04-04
        [shiftName] => Long Day
        [1] => Long Day
    )
是否可以将数据设置为变量

例如:

$date = 2014-04-06;
$shiftname = Long Day;
如果是这样,从结果来看,我如何使用循环将其放入这样的表中

-+--------------------------------------+- 
 | 2014-04-02 | 2014-04-03 | 2014-04-06 |
-+--------------------------------------+-
 | Long Day   | Long Day   | Long Day   |
-+--------------------------------------+-

如果要将数组中的信息提取到单个变量中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
如果要将信息保存到阵列中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
要将其显示为表格,请尝试以下操作:

// Create an empty Array for the dates and one for the shift names
$dates = array(); $shiftNames = array();
// Initiate the table string
$table = "<table>";

// Save each date and shift from your original array into the date or shiftName array    
foreach($your_array as $sub_array) {
    $dates[] = $sub_array['date'];
    $shiftNames[] = $sub_array['shiftName'];
}

// Create a new row in your table
$table .= "<tr>";

// for each date insert a cell into your table and the first row
foreach($dates as $date) {
   $table .= "<td>".$date."</td>";
}

// close the first row open a new row
$table .= "</tr><tr>";

// for each shift name insert a cell into the table and the second row with the shfitName
foreach($shiftNames as $shiftName) {
    $table .= "<td>".$shiftName."</td>";
}

// close the second row and close the table
$table .= "</tr></table>";

// Echo the table to where ever you want it to have
echo $table;
//为日期和班次名称创建一个空数组
$dates=array()$shiftNames=array();
//启动表字符串
$table=“”;
//将每个日期和班次从原始数组保存到日期或班次名称数组中
foreach($sub_数组){
$dates[]=$sub_数组['date'];
$shiftNames[]=$sub_数组['shiftName'];
}
//在表中创建新行
$table.=”;
//对于每个日期,在表和第一行中插入一个单元格
foreach($日期作为$日期){
$table.=“.$date.”;
}
//关闭第一行打开新行
$table.=”;
//对于每个班次名称,在表中插入一个单元格,并在第二行插入shfitName
foreach($shiftName作为$shiftName){
$table.=''.$shiftName.'';
}
//关闭第二行并关闭表格
$table.=”;
//把桌子放在你想要的地方
echo$表;

如果要将数组中的信息提取到单个变量中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
如果要将信息保存到阵列中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
要将其显示为表格,请尝试以下操作:

// Create an empty Array for the dates and one for the shift names
$dates = array(); $shiftNames = array();
// Initiate the table string
$table = "<table>";

// Save each date and shift from your original array into the date or shiftName array    
foreach($your_array as $sub_array) {
    $dates[] = $sub_array['date'];
    $shiftNames[] = $sub_array['shiftName'];
}

// Create a new row in your table
$table .= "<tr>";

// for each date insert a cell into your table and the first row
foreach($dates as $date) {
   $table .= "<td>".$date."</td>";
}

// close the first row open a new row
$table .= "</tr><tr>";

// for each shift name insert a cell into the table and the second row with the shfitName
foreach($shiftNames as $shiftName) {
    $table .= "<td>".$shiftName."</td>";
}

// close the second row and close the table
$table .= "</tr></table>";

// Echo the table to where ever you want it to have
echo $table;
//为日期和班次名称创建一个空数组
$dates=array()$shiftNames=array();
//启动表字符串
$table=“”;
//将每个日期和班次从原始数组保存到日期或班次名称数组中
foreach($sub_数组){
$dates[]=$sub_数组['date'];
$shiftNames[]=$sub_数组['shiftName'];
}
//在表中创建新行
$table.=”;
//对于每个日期,在表和第一行中插入一个单元格
foreach($日期作为$日期){
$table.=“.$date.”;
}
//关闭第一行打开新行
$table.=”;
//对于每个班次名称,在表中插入一个单元格,并在第二行插入shfitName
foreach($shiftName作为$shiftName){
$table.=''.$shiftName.'';
}
//关闭第二行并关闭表格
$table.=”;
//把桌子放在你想要的地方
echo$表;

如果要将数组中的信息提取到单个变量中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
如果要将信息保存到阵列中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
要将其显示为表格,请尝试以下操作:

// Create an empty Array for the dates and one for the shift names
$dates = array(); $shiftNames = array();
// Initiate the table string
$table = "<table>";

// Save each date and shift from your original array into the date or shiftName array    
foreach($your_array as $sub_array) {
    $dates[] = $sub_array['date'];
    $shiftNames[] = $sub_array['shiftName'];
}

// Create a new row in your table
$table .= "<tr>";

// for each date insert a cell into your table and the first row
foreach($dates as $date) {
   $table .= "<td>".$date."</td>";
}

// close the first row open a new row
$table .= "</tr><tr>";

// for each shift name insert a cell into the table and the second row with the shfitName
foreach($shiftNames as $shiftName) {
    $table .= "<td>".$shiftName."</td>";
}

// close the second row and close the table
$table .= "</tr></table>";

// Echo the table to where ever you want it to have
echo $table;
//为日期和班次名称创建一个空数组
$dates=array()$shiftNames=array();
//启动表字符串
$table=“”;
//将每个日期和班次从原始数组保存到日期或班次名称数组中
foreach($sub_数组){
$dates[]=$sub_数组['date'];
$shiftNames[]=$sub_数组['shiftName'];
}
//在表中创建新行
$table.=”;
//对于每个日期,在表和第一行中插入一个单元格
foreach($日期作为$日期){
$table.=“.$date.”;
}
//关闭第一行打开新行
$table.=”;
//对于每个班次名称,在表中插入一个单元格,并在第二行插入shfitName
foreach($shiftName作为$shiftName){
$table.=''.$shiftName.'';
}
//关闭第二行并关闭表格
$table.=”;
//把桌子放在你想要的地方
echo$表;

如果要将数组中的信息提取到单个变量中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
如果要将信息保存到阵列中,请按以下方式执行:

$date = $your_array[0]['date'];
$shiftname = $your_array[0]['shiftName'];
$your_array[0]['date'] = $date;
$your_array[0]['shiftName'] = $shiftname;
要将其显示为表格,请尝试以下操作:

// Create an empty Array for the dates and one for the shift names
$dates = array(); $shiftNames = array();
// Initiate the table string
$table = "<table>";

// Save each date and shift from your original array into the date or shiftName array    
foreach($your_array as $sub_array) {
    $dates[] = $sub_array['date'];
    $shiftNames[] = $sub_array['shiftName'];
}

// Create a new row in your table
$table .= "<tr>";

// for each date insert a cell into your table and the first row
foreach($dates as $date) {
   $table .= "<td>".$date."</td>";
}

// close the first row open a new row
$table .= "</tr><tr>";

// for each shift name insert a cell into the table and the second row with the shfitName
foreach($shiftNames as $shiftName) {
    $table .= "<td>".$shiftName."</td>";
}

// close the second row and close the table
$table .= "</tr></table>";

// Echo the table to where ever you want it to have
echo $table;
//为日期和班次名称创建一个空数组
$dates=array()$shiftNames=array();
//启动表字符串
$table=“”;
//将每个日期和班次从原始数组保存到日期或班次名称数组中
foreach($sub_数组){
$dates[]=$sub_数组['date'];
$shiftNames[]=$sub_数组['shiftName'];
}
//在表中创建新行
$table.=”;
//对于每个日期,在表和第一行中插入一个单元格
foreach($日期作为$日期){
$table.=“.$date.”;
}
//关闭第一行打开新行
$table.=”;
//对于每个班次名称,在表中插入一个单元格,并在第二行插入shfitName
foreach($shiftName作为$shiftName){
$table.=''.$shiftName.'';
}
//关闭第二行并关闭表格
$table.=”;
//把桌子放在你想要的地方
echo$表;
应该对您有用。它和你描述的一模一样

对于使用相同密钥的多个数组,可能存在一些警告。但这就提出了一个观点:变量分配的自动化不可避免地有缺点;对作业相对具体一些是很好的。如果需要提取每个数组,则必须迭代并为键或其他对象提供前缀以避免冲突。

应该对您有用。它和你描述的一模一样

对于使用相同密钥的多个数组,可能存在一些警告。但这就提出了一个观点:变量分配的自动化不可避免地有缺点;对作业相对具体一些是很好的。如果需要提取每个数组,则必须迭代并为键或其他对象提供前缀以避免冲突。

应该对您有用。它和你描述的一模一样

对于使用相同密钥的多个数组,可能存在一些警告。但这就提出了一个观点:变量分配的自动化不可避免地有缺点;对作业相对具体一些是很好的。如果需要提取每个数组,则必须迭代并为键或其他对象提供前缀以避免冲突。

应该对您有用。是的