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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:51:40+00:00 2026-05-25T23:51:40+00:00

fegtcsv does the work for fetching data of csv file in php I wrote

  • 0

fegtcsv does the work for fetching data of csv file in php
I wrote this code to fetch data from my input file

<?php
$file_handle = fopen("input.csv", "r");
while(!feof($file_handle)){
    $line_of_text=fgetcsv($file_handle,3020);
    $a= $line_of_text[1];
    $b=$line_of_text[2];
    $c=$line_of_text[3];
    $d=$line_of_text[4];
   }
   fclose($file_handle);
?>

now what actually i want is to do is some matematical operation between third data ( which is $c ) in each line. for eg. add the $c in line 1 with $c of line 2. and some more mathematical operation. I will be able to do this only if I can get those data as c1, which would be $c of first line c2 which would be $c of second line. But I din’t find how to do that. the above script prints every line of the file. I have no control over which data of which line ( or row ) to print. how do I do that ? any thing I am missing to read or learn ? please let me know.

  • 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-25T23:51:41+00:00Added an answer on May 25, 2026 at 11:51 pm

    Every time you call fgetcsv you get another line. Therefore:

    while (!feof($file_handle)){
        $line_of_text = fgetcsv($file_handle, 3020);
        $a1 = $line_of_text[1];
        $b1 = $line_of_text[2];
        $c1 = $line_of_text[3];
        $d1 = $line_of_text[4];
    
        $line_of_text = fgetcsv($file_handle, 3020);
        $a2 = $line_of_text[1];
        $b2 = $line_of_text[2];
        $c2 = $line_of_text[3];
        $d2 = $line_of_text[4];
    
        $line_of_text = fgetcsv($file_handle, 3020);
        $a3 = $line_of_text[1];
        $b3 = $line_of_text[2];
        $c3 = $line_of_text[3];
        $d3 = $line_of_text[4];
    
        echo $a1 + $a2 + $a3;
    }
    

    Tip: you can also use loops within loops…

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

Sidebar

Related Questions

I have used following code for retrieving content from a csv file. <?php $fo
I've been working on this simple code that puts a CSV file into a
I am using PHP to import a CSV file, which originates from an excel
I need to create a CSV file from a PHP array, I'm aware of
Can someone kindly provide a code to create an array from a CSV file
I'm now using this code to import csv data into my database.(Thanks to Francis
I read in a csv file by using a while loop: while (($data =
I've got a CSV file with two sets of data in it [its pulled
I am uploading email addresses from a CSV file, via fgetcsv() , into a
i have CSV Files which i read by: Why does this CSV not be

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.