Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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,我有这样的代码 $table=table_name; $sql="SELECT * from $table where student_id='X' and class='Y' and section='Z'"; $result=$conn->query($sql); while($row=mysqli_fetch_array($result) { $column[]=$row; } //printing $colum

我有这样的代码

  $table=table_name;
  $sql="SELECT * from $table where student_id='X' and
        class='Y' and section='Z'";
  $result=$conn->query($sql);
  while($row=mysqli_fetch_array($result)
  { 
    $column[]=$row; 
  }
//printing $columns array
print_r($column);
column[0]=sno;
column[1]=student_id;
column[2]=exan_name;
column[3]=class; and so on..
输出

ARRAY ( [0] => ARRAY ( [0] => 1 [SNO] => 1 [1] => 21DBAAACAC0 [STUDENT_ID] => 21DBAAACAC0 [2]
 => WEEKEND [EXAM_NAME] => WEEKEND [3] => 8TH-STANDARD [CLASS] => 8TH-STANDARD [4] =>
 A [SECTION] => A [5] => 0 [PERCENTAGE] => 0 [6] => 2021-03-29 [CONDUCTED_DATE]
 => 2021-03-29 [7] => [TELUGU] => [8] => 35 [ENGLISH] => 35 [9] => [MATHEMATICS] => [10] =>
 [SOCIAL] => [11] => [HINDI] => [12] => [SCIENCE] => [13] => [NATURAL SCIENCE] => ) )
sno(column 1 name)
student_name(column 2 name)
student_id(column 3 name)...up to size-1
我需要将列名存储到这样的数组中

  $table=table_name;
  $sql="SELECT * from $table where student_id='X' and
        class='Y' and section='Z'";
  $result=$conn->query($sql);
  while($row=mysqli_fetch_array($result)
  { 
    $column[]=$row; 
  }
//printing $columns array
print_r($column);
column[0]=sno;
column[1]=student_id;
column[2]=exan_name;
column[3]=class; and so on..
最终,我需要将(动态创建的表的)列名放入数组中

您可以使用:

while ($row = $result->fetch_assoc()) {
    //code here
}
<?php 
   
   $new = call_user_func_array('array_merge', 'array name here');
   for($i=0;$i<sizeof($new)-1;$i++)
    {
      echo $new[$i]."<br>"; 
    }
?>
您将拥有如下关联数组:

$row(
    "column_key0" => "column_value0",
    "column_key1" => "column_value"
    //and so on
);
然后您可以使用foreach访问它

foreach ($row as $column_key => $value) {
    //code here ($column_key is the name of your column)
};
然后你可以做你想做的事情,比如把它保存在另一个数组中,检查是否有重复项,或者只是根据你的需要使用它。 这样,如果不知道表结构,也可以使用列名。 因此:


是最终的结果

使用以下代码获取关联数组的键

<?php 
   
   $new = call_user_func_array('array_merge', 'array name here');
   for($i=0;$i<sizeof($new)-1;$i++)
    {
      echo $new[$i]."<br>"; 
    }
?>

forech不工作它为每个键的值返回数组……它显示->警告:在C:\xampp\htdocs\sms template\architectui html pro\gaurdian.php第282行返回数组0=>array 1=>array…..很抱歉,您现在正在编辑答案