Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:05:30+00:00 2026-05-26T21:05:30+00:00

I have two files one is a tab delimited and one is a csv

  • 0

I have two files one is a tab delimited and one is a csv which is comma seperated and they both get uploaded and I need to combine them into one csv thats sorted…here is my code so far

$txt = glob('files/*.txt*');
$csv = glob('files/*.csv*');
$test = array();
if (($handle = fopen($csv[0], "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
            $test[$c][] = $data[$c];
        }
    }
    fclose($handle);
}

if (($handle = fopen($txt[0], "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
        $num = count($data);
        $row++;
        for ($c=0; $c < $num; $c++) {
          $test[$c][] = $data[$c];
        }
    }
    fclose($handle);
}

the test array has the full array of both but i am running into a few problems first the $test array is like this

[0] => Array
       (
           [0] => Edit
           [1] => y
           [2] => y
           [3] => y
           [4] => y
           [5] => y
           [6] => y
           [7] => y
           [8] => y
           [9] => y
[1] => Array
    (
        [0] => Event
        [1] => Carolina Panthers PSL
        [2] => Florida
        [3] => Carolina Panthers PSL
        [4] => Apple
        [5] => Carolina Panthers PSL
        [6] => Carolina Panthers PSL
        [7] => Carolina Panthers PSL
        [8] => Carolina Panthers PSL
        [9] => Carolina Panthers PSL
        [10] => Carolina Panthers PSL
[2] => Array
     (
         [0] => Venue
         [1] => Bank of America Stadium 
         [2] => Washington Mutual 
         [3] => Bank of America Stadium 
         [4] => Apple Inc
         [5] => Bank of America Stadium 
         [6] => Bank of America Stadium 
         [7] => Bank of America Stadium 
         [8] => Bank of America Stadium 
         [9] => Bank of America Stadium 
         [10] => Bank of America Stadium 
         [11] => Bank of America Stadium 
         [12] => Bank of America Stadium

How do i create a new csv with everything but i need to sort by event name and this format for the test array seems off..any ideas what im doing wrong…

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:05:31+00:00Added an answer on May 26, 2026 at 9:05 pm

    Assuming the column names are on the first line of your file this should work:

    $txt = glob('files/*.txt*');
    $csv = glob('files/*.csv*');
    $test = array();
    $headers = array();
    if (($handle = fopen($csv[0], "r")) !== FALSE) {
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        if (empty($headers)) {
          for ($c=0; $c < $num; $c++) {
            $headers[$c] = $data[$c];
          }
        }
        else {
          $line = array();
          for ($c = 0; $c < $num; $c++) {
            $line[$headers[$c]] = $data[$c];
          }
          $test[] = $line;
        }
      }
    }
    
    if (($handle = fopen($csv[0], "r")) !== FALSE) {
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        $line = array();
        for ($c = 0; $c < $num; $c++) {
          $line[$headers[$c]] = $data[$c];
        }
        $test[] = $line;
      }
    }
    

    That should give you an array like

    [0] => Array
    (
           [Edit] => y
           [Event] => Carolina Panthers PSL
           [Venue] => Bank of America Stadium,
           ...
    [1] => Array
    (
    
           [Edit] => y
           [Event] => Florida
           [Venue] => Washington Mutual ,
    ...
    

    Then you can use usort on the array to sort it by the Event key with a custom callback. See the docs page for that function for loads of examples, or try this:

    function my_sort($a, $b) {
      return strcmp($a['Event'], $b['Event']);
    }
    usort($test, 'my_sort');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am have two xml files.. I first get one and loop through it
I have two tab-delimited genome sequence files (SAM format), and I would like to
I have two tab delimited files, file 1 contains identifiers and file 2 has
I have two files one with senators who are retiring and one of complete
I have two template files: one for the form (loginFormTemplate) and one for the
Here I am trying to implement the jQuery I have two main files one
Say I have two files where there is one number per line File 1
I have two files. file1 has the data like belowing containing only one column.
Is it possible to have two app.config files where one app.config serves as a
I have the two following text files: First one: chr10 1000 1001 DEL 2.4807

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.