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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:27:00+00:00 2026-05-28T08:27:00+00:00

I upload a csv and expload it to an array. array(6) { [0]=> string(64)

  • 0

I upload a csv and expload it to an array.

array(6) {
  [0]=>
  string(64) "Criteron A-1 bla ,Criteron A-2 bla,Criteron A-3 bla,Criteron A-4 bla,Criteron A-5 bla"
  [1]=>
  string(64) "Criteron B-1 bla,Criteron B-2 bla,Criteron B-3 bla,Criteron B-4 bla,Criteron B-5 bla"
  [2]=>
  string(51) "Criteron C-1 bla,Criteron C-2 bla,Criteron C-3 bla,Criteron C-4 bla"
  [3]=>
  string(38) "Criteron D-1 bla,Criteron D-2 bla,Criteron D-3 bla"
  [4]=>
  string(64) "Criteron E-1,Criteron E-2,Criteron E-3,Criteron E-4,Criteron E-5"
  [5]=>
  string(51) "Criteron F-1,Criteron F-2,Criteron F-3,Criteron F-4"
}

The original csv has 6 rows and max 5 columns as you see in the above.

In order to put these data in a table, I need to know number of rows and maximum number of columns.

I can find number of rows by using count(). I am thinking to use substr_count() of comma “,” for each array and find max then add one to that max to find out the max number of column. (I haven’t figure it out how to code the second part yet, though)

I am wondering if you know a better way.

Thanks in advance.

  • 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-05-28T08:27:01+00:00Added an answer on May 28, 2026 at 8:27 am

    You can get the max number of columns using max(), array_map() and explode()

    $maxColumns = max(array_map(function($row){
        return count(explode(',', $row));
    }, $rows));
    
    1. array_map runs the anonymous function for every row in the array, creating a new array with its results.

    2. For each row, count(explode()) counts the number of columns seperated by commas in it.

    3. max() runs on the array of column counts, returning the largest one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am expecting users to upload a CSV file of max size 1MB to
I frequently upload CSV files to a MySQL db. It is very convenient to
I need to upload a csv file to a server. works fine for smaller
I'm currently working on a project where users can upload datasets in CSV format.
I need to upload a massive (16GB, 65+ million records) CSV file to a
I need to upload a .csv file and save the records in bigtable. My
I am trying to upload large CSV files onto GAE using a zip using
I'm trying to upload this CSV file onto my table in pgsql, but I'm
What is the best way to upload a CSV file through a Java servlet
I am using the FileHelpers libraries to upload a CSV file to SQL Server.

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.