Jump to content

Keep elements in array in while


ankme

Recommended Posts

I have a file that contains, among others, some links to other files. Those files contain links to other files and so on.

What I want to do is to check if a file has already been opened, and if this is true I want the file not to be opened again.

For this I created an array, but when the code returns to the first file the array is reseted. Can someone please help me?

This is the code I created (I`m a beginer in php). Thanks

 

function readImportFiles($taxonomyFile, $target_path, $fileName='', $ArrayOfTaxonomies = array())

{

 

while(!feof($taxonomyFile))

{

$line = fgets($taxonomyFile);

//code for getting the $schemaLocation

if ($schemaLocation && !in_array($schemaLocation, $ArrayOfTaxonomies))

{

$ArrayOfTaxonomies[]= $schemaLocation;

$importSchema = fopen($schemaLocation, "r");

$target_path = substr($schemaLocation, 0, (strlen($schemaLocation) - strlen(strrchr($schemaLocation, "/"))));

readImportFiles($importSchema, $target_path, $schemaLocation, $ArrayOfTaxonomies);

 

}

}

}

Link to comment
Share on other sites

Pass the array as a reference so that any changes you make are made to the original copy.

 

function readImportFiles($taxonomyFile, $target_path, $fileName='', &$ArrayOfTaxonomies = array()) // << Pass array as reference
{

  while(!feof($taxonomyFile))
  {
    $line = fgets($taxonomyFile);
    //code for getting the $schemaLocation
    if ($schemaLocation && !in_array($schemaLocation, $ArrayOfTaxonomies))
    {
      $ArrayOfTaxonomies[]= $schemaLocation;
      $importSchema = fopen($schemaLocation, "r");
      $target_path = substr($schemaLocation, 0, (strlen($schemaLocation) - strlen(strrchr($schemaLocation, "/"))));
      readImportFiles($importSchema, $target_path, $schemaLocation, $ArrayOfTaxonomies);
    }
  }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.