1

I am trying to transpose the array, Here is my current code: I apologise if it looks like I am completely stupid, but I am relatively new to php and programming in general, so this task has been very difficult!! Thank you so much in advance.

$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);
Clea A
  • 23
  • 5
  • `function transpose($array) { array_unshift($array, null); return call_user_func_array('array_map', $array); } $new_data = transpose($store1);` – Mark Baker Nov 25 '16 at 23:33
  • Interesting page. Dupe not closed as a dupe. Answer as a comment. Comment as an answer. – mickmackusa Apr 07 '23 at 13:37

0 Answers0