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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:37:10+00:00 2026-06-14T05:37:10+00:00

$$I have a bunch fo text files I’d like to eventually explode into arrays,

  • 0

$$I have a bunch fo text files I’d like to eventually explode into arrays, but since the amount of text files is dynamically chosen via user input, I can’t just initialize them one-by-one and instead am opting for a for loop.

For the sake of example, three text files I have contain the following (excuse the \n, imagine it’s a line break):

file1.txt = 1 \n 2 \n 3

file2.txt = 6 \n 2 \n 7

file3.txt = 9 \n 1 \n 9

The code I attempted:

<?php
    for ($i = 1; $i <= 3; $i++) {
        list($line1[$i], $line2[$i], $line3[$i]) = file("public_html/texts/file".$i.".txt");
?>

This obviously doesn’t work, but I’m not sure why. In the end, the result should be:

$line1[1] = 1
$line2[1] = 2
$line3[1] = 3
$line1[2] = 6
$line2[2] = 2
$line3[2] = 7
$line1[3] = 9
$line2[3] = 1
$line3[3] = 9

How do I go about doing this?

edit; fixed typo.

  • 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-14T05:37:11+00:00Added an answer on June 14, 2026 at 5:37 am
    for($i = 1; $i <= 3; $i++) {
    
        $lines = file('public_html/texts/file' . $i . '.txt');
    
        $line1[] = $lines[0];
        $line2[] = $lines[1];
        $line3[] = $lines[2];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of text files with tab delimited data, like so X
I have to take a bunch of columnar text files and integrate them into
I would like to automatically pre-translate a bunch of text files that I have
I have some text files with a whole bunch of info in them. Most
I have a bunch of log files which are pure text. Here is an
So, I have a string of text: string with a bunch of links but
I have a bunch of text files that are encoded in ISO-8851-2 (have some
I have a bunch of text files where I want to add a line
My app reads a bunch of text files. At the moment I have saved
I have a bunch of text files that were encoded in UTF-8 . 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.