2016-11-25 5 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

'function transpose ($ array) { array_unshift ($ array, null); return call_user_func_array ('array_map', $ array); } $ new_data = transpose ($ store1); ' –

ответ

0

Я не могу комментировать, поэтому я попрошу вас здесь.

Чтобы получить лучший ответ, вы должны сообщить аудитории, что находится внутри вашего файла (1.txt). Is 1.txt csv файл или он разделен пробелами?
Также важно знать, что вы хотите сделать после переноса массива