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 7877851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:29:42+00:00 2026-06-03T03:29:42+00:00

I have a CSV file with thousands of numbers underneath each other. Let’s simplify

  • 0

I have a CSV file with thousands of numbers underneath each other. Let’s simplify by using this:

4
7
1
9
3
3
8
6
2

What I want is to output an array with 3 numbers per key (imploded by a comma):

array (
  [0] => 4,7,1
  [1] => 9,3,3
  [2] => 8,6,2
)

I’ve managed to get to this, reading the CSV:

$path = "data.csv";
$row = 1;
if (($handle = fopen($path, "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, "\r\n")) !== FALSE) {
    $cell = 0;
    $table[$row][$cell] = $data[0];
    $cell++;
  }
  fclose($handle);
}

I am just confused as to where an how I have to up $row and $cell to get the output I want. Could you help?

  • 1 1 Answer
  • 0 Views
  • 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-06-03T03:29:44+00:00Added an answer on June 3, 2026 at 3:29 am

    Use this, I tested and works:

    <?php
    $path = "data.csv";
    $array = explode("\n", file_get_contents("data.csv"));
    $numbers = array();
    foreach(array_chunk($array, 3) as $number){
        $numbers[] = implode(", ", $number);
    }
    print_r($numbers);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a CSV file with thousands of lines similar to this one
I have csv file that looks like this: artist,year,id,video_name,new_video_id,file_root_name,video_type ,,,,,, Clay Aiken,1,clay_aiken,Sorry Seems To
I have CSV file and Macro in VBA. I want to open CSV file
I have some lines in a CSV file like this: 1000001234,Account Name,0,0,3,711.32,0,0,18,629.64,22,340.96,COD,20,000.00,Some string,Some string
I have a file that I saved as a CSV file using Excel (I
I am using PHP to expose vehicle GPS data from a CSV file. This
I have csv file with a line that looks something like this: ,,,,,,,,,, That's
I have csv file like this: item,#RGB item1,#ffcc00 item1,#ffcc00 item1,#ff00cc item2,#00ffcc item2,#ffcc00 item2,#ffcc00 item2,#ffcc00
I want to use mysql LOAD DATA to import CSV file. Numbers in my
I have a CSV file that looks like this, where time is a UNIX

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.