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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:16:49+00:00 2026-06-12T08:16:49+00:00

I am writing a utility to do some data loading from text files. I

  • 0

I am writing a utility to do some data loading from text files. I have a collection of dictionary files that i am processing into arrays that define the structure of the data files. Yes, i could use classes or otherwise, but using arrays, i have been stumped.

Let’s say i have 3 files that i read and load into arrays. When i read the arrays, the 3rd instance has elements of the second despite trying to use unset and other things. What am I missing? I am on cygwin using php 5.3.16

Following are examples of list, but not the real lists. so, please disregard the substr statements as they are not real

fname c 1 16
lname c 17 30

addr c 1 20
city c 21 30
state c 31 40
zip n 41 45

bday d 1 9
ssn c 10 18

when loading with the code below, the 3rd array has elements from the second, namely bday, ssn, state and zip.

$cnt = 0;
while ($s = fgets($fp, 1024)) {
    $fldprops = array();
    $fldprops[0] = trim(substr($s,0,8));
    $fldprops[1] = trim(substr($s,9,1));
    $fldprops[2] = trim(substr($s,11,3));
    $fldprops[3] = trim(substr($s,15,3));
    $flds[$cnt] = $fldprops;
    $cnt++;
    unset($fldprops);
}

I had thought either one of $fldprops = array(); or unset() would clear the array but it is not working.

Update: I mistook the point of failure. it is not apparently at writing to the outer array, but in reading. As i mentioned in a comment, later in the code, i have a foreach loop and here it is failing:

foreach ($flds as $fldprop) {
     var_dump($fldprop);
}

here, i get bday, ssn, state and zip (the last two entries of the second array merged with the 3rd array).

  • 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-12T08:16:50+00:00Added an answer on June 12, 2026 at 8:16 am

    This is the output I am getting:

    <?php
        $flds = array();
        $cnt = 0;
        $s = "HelloWorldNiceToSeeYou";
        $fldprops = array();
        $fldprops[0] = trim(substr($s,0,8));
        $fldprops[1] = trim(substr($s,9,1));
        $fldprops[2] = trim(substr($s,11,3));
        $fldprops[3] = trim(substr($s,15,3));
        $flds[$cnt] = $fldprops;
        $cnt++;
        unset($fldprops);
        var_dump($flds, $cnt, $fldprops);
    ?>
    

    Output:

    <br />
    <b>Notice</b>:  Undefined variable: fldprops in <b>/code/MQpnac</b> on line <b>13</b><br />
    array(1) {
      [0]=>
      array(4) {
        [0]=>
        string(8) "HelloWor"
        [1]=>
        string(1) "d"
        [2]=>
        string(3) "ice"
        [3]=>
        string(3) "oSe"
      }
    }
    int(1)
    NULL
    
    PHP Notice:  Undefined variable: fldprops in /code/MQpnac on line 13
    

    So PHP is doing it right. Check out live at: http://codepad.viper-7.com/MQpnac

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

Sidebar

Related Questions

I'm writing a utility module for easy handling of data text files. I have
I'm writing a console utility to do some processing on files specified on the
I'm writing a little utility to load Entity Data Models from an assembly and
On a regular basis I find myself writing little utility programs that use some
I'm writing a utility to deploy some MSIs on remote machines. Do MSI files
I'm writing a utility in Python that will attach changed files in Subversion to
My task is to filter some data from perl script with external utility (the
I'm writing a tweak utility that modifies some keys under HKEY_CLASSES_ROOT . All works
I am writing a small wxPython utility. I would like to use some event
I'm writing a utility program with C# in WPF that allows users to create

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.