Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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_Matrix_Transpose - Fatal编程技术网

在php中转置数组

在php中转置数组,php,matrix,transpose,Php,Matrix,Transpose,我正在尝试转换数组, 这是我目前的代码:如果看起来我完全愚蠢,我道歉,但我对php和编程一般来说是比较新的,所以这个任务非常困难!! 事先非常感谢你 $store1 = file("1.txt"); $store1 = array(); $file1 = fopen("1.txt", "r") or die("Unable to open file!"); //put the .txt file into an array while (!feof($file1)) { $line=f

我正在尝试转换数组, 这是我目前的代码:如果看起来我完全愚蠢,我道歉,但我对php和编程一般来说是比较新的,所以这个任务非常困难!! 事先非常感谢你

$store1 = file("1.txt");
$store1 = array();
 $file1 = fopen("1.txt", "r") or die("Unable to open file!");   

//put the .txt file into an array
while (!feof($file1))
{
$line=fgets($file1);

//process line however you like
$line=trim($line);

//add to array
$store1[]=$line;

}

///trying to transpose matrix the array in this function..
 function transposeArray($store1)
{
if(is_object($store1))
    $store1 = get_object_vars($store1);

if(!is_array($store1))
    return $store1;

$new_data = array();
//var_dump($data);
foreach ($store1 as $key=>$record);
    foreach ($record as $index=>$value);
        $new_data[$index][$key] = $value;
    //var_dump($new_data);
    return $new_data;
echo $new_data[1];
}

//trying to call the function..
   transposeArray($store1);

fclose($file1);

我不能发表评论,所以我会请你进来

为了得到更好的答案,你需要让读者知道你的文件(1.txt)中有什么内容。 1.txt是csv文件还是用空格分隔?

同样重要的是要知道在转置数组后要做什么,我不能发表评论,所以我会在这里问你

为了得到更好的答案,你需要让读者知道你的文件(1.txt)中有什么内容。 1.txt是csv文件还是用空格分隔?
同样重要的是,要知道在转置数组后要执行什么操作

函数转置($array){array\u unshift($array,null);返回call\u user\u func\u array('array\u map',$array);}$new\u data=transpose($store1)
函数转置($array){array_unshift($array,null);返回调用_user_func_array('array_map',$array);}$new_data=transpose($store1)