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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:30:14+00:00 2026-05-22T14:30:14+00:00

UPDATE: I realized that the issue was I was using print instead of echo

  • 0

UPDATE: I realized that the issue was I was using print instead of echo to print the data, so it was showing the array instead of the data within it. Thanks a ton guys!

I currently have a text file that looks like this:

0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0

And I’m using this function:

function rFile($fileName){
$resultF = fopen($fileName, "r") or die("can't open file");
$array = array(); //Create the first dimension of a 2D array
$i=0;
while(!feof($resultF)){
  $line = fgets($resultF);
  $line = trim($line, "\n");
  $tokens = explode(",",$line);
  $array[$i]=array(); //Create the second dimension of the 2D array
  $tokenCount = sizeof($tokens);
  for($j=0; $j<$tokenCount; $j++){
    $array[$i][$j] = $tokens[$j];
  }
  $i++;
 }
return $array;
  }

Essentially, it’s supposed to read through the file, explode each “0” and store it in a 2D array, $array. For some reason it returns this:

Array[0]
Array[1]
Array[2]
....etc etc

Anyone know what I did wrong?

  • 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-22T14:30:14+00:00Added an answer on May 22, 2026 at 2:30 pm

    You’re going about it the hard way, by using for loops and counters. By using PHP’s $array[] = $val append syntax, you can save a lot of effort here.

    // all the file handling code...
    
    while(!feof($resultF)){
      $line = fgets($resultF);
      $line = trim($line, "\n");
      $tokens = explode(",",$line);
    
      // Append the line array.
      $array[] = $tokens; //Create the second dimension of the 2D array
    }
    
    return $array;
    

    Or to be even more concise:

    $array[] = explode(",",$line);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: I realized that the initWithFrame method is never called, so I placed my
Update: Thanks for closing my question because it might solicit opinions or discussion. That
I try to realize a link (in fact many links) that update a table
UPDATE: Thanks to everyone for the responses. I didn't realize document.write() was deprecated. Add
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
As many developers will be I'm producing web based application that are using AJAX
I've run into a weird issue that has had me scratching my head for
I am using the GA Data Export API to interact with Google Analytics and
Update: Solved, with code I got it working, see my answer below for the

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.