格式化Excel文件问题

I have a program that turns a file into an excel file but for some reason my phone and email fields get switched. It looks like this -

firstname   lastname    email   phone
test                            bi@gmail.com
test            d               813-767 leighmimail.com
test            Pds         888-413 Bperotects.com

the email and phone should be switched

Code:

   <?php
session_start();

$num = $_SESSION['num'];
    $firstname =  $_SESSION['firstnameexport'];
    $lastname = $_SESSION['lastnameexport'];
    $email = $_SESSION['emailexport'];
    $phone = $_SESSION['phoneexport'];

    for($i =0; $i< $num; $i++){
    $data[$i] = array(
    "firstname" => $firstname[$i] , "lastname" => $lastname[$i], "email" => $email[$i], "phone" => $phone[$i]);
    }

function cleanData(&$str)
  {
    $str = preg_replace("/\t/", "\\t", $str);
    $str = preg_replace("/?
/", "\
", $str);
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
  }

// filename for download
  $filename = "website_data_" . date('Ymd') . ".xls";

  header("Content-Disposition: attachment; filename=\"$filename\"");
  header("Content-Type: application/vnd.ms-excel");

  $flag = false;
  foreach($data as $row) {
    if(!$flag) {
      // display field/column names as first row
      echo implode("\t", array_keys($row)) . "
";
      $flag = true;
    }
     array_walk($row, 'cleanData');
    echo implode("\t", array_values($row)) . "
";
  }


unset($_SESSION['num'],$_SESSION['firstnameexport'],$_SESSION['lastnameexport'],$_SESSION['emailexport'],$_SESSION['phoneexport']);
?>

Thank you for your time!

Fixed it - all I had to do was switch some of the session variables out so it would give the correct value for the right column.

Thank you for your time!