2016-11-25 6 views
1

配列を転置しようとしています ここに私の現在のコードがあります:私はまったくばかげているように見えますが、比較的新しいPHPとプログラミングに一般的です。非常に難しかった!! ありがとうございます。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); 
+0

'関数の転置($配列){ するarray_unshift($配列、null)を転置した後に何をしたいのかを知ることが重要です。 戻り値call_user_func_array( 'array_map'、$ array); } $ new_data = transpose($ store1); ' –

答えて

0

私はコメントできませんので、ここでお尋ねします。

あなたのファイル(1.txt)の中に何が入っているかを視聴者に知らせる必要があります。 1.txtはcsvファイルですか、またはスペースで区切られていますか?
はまた、あなたが配列

関連する問題