troubleshooting Question

Problem with an Loading/Extracting data from an Array with PHP

Avatar of dogsareit
dogsareitFlag for United States of America asked on
PHP
9 Comments1 Solution23 ViewsLast Modified:
I am having problems with loading and extracting data in  an array.
Since  I will be using the information in various function, reading and adding to it  and so forth,.
I declared it at in the global declaration section at the beginning of my application.
I also declare a global index for it
Each filename has information associated with the filename - such  as supplier code and etc.
I can not seem to load the array correctly nor be able to extract the data for each filename.
I have tried various ways and I am unsuccessful.
I do know all the information going into the array is valid. I have verified that - I just can not seem to load/extract the data correctly.

// DEFINE GLOBAL AGENCY ARRAY AND INDEX - USED TO STUFF FILENAME INFO INTO IT

$_SESSION['GlobalAgencyIndex'] = 0;

$_SESSION['GlobalAgencyArray'] = array(
         'strAgencyFileName' => '',
         'strAgencySupplierCode'=> '',
         'strAgencyConfNbr' => '',
         'strAgencyStatus' => ''); 

And this is one of my functions that uses it:
Sorry it's so long.
Function RtnWrtAgencyFolder($strSupplierCode,$strConfirmNbr,$strSwitch,$strFileData)
{ 
   echo '<BR><BR>AT RtnWrtAgencyFolder';

   $strSwitch = 'AGENCY';
   $strStatus = 'NOTUPLOADED';
   
   $folder_path = $_SESSION['TmpAgencyFolder'];
   $strReplaceFolderPath = $_SESSION['TmpAgencyFolder'];
   $strAWSReplacePath = $_SESSION['AgencyAWS'];
   $strFileDataArray = $_SESSION['SavedFileData'];
   // DEFINE A TEMP ARRAY
   $index = sizeof($_SESSION['GlobalAgencyArray']);
   $strTmpCount = 0;
   echo '<BR>sizeof $_SESSION[GlobalAgencyArray]:  ' .  $index;
   
   foreach($strFileDataArray as $wrkdata)
        {
         
          $wrkTestData = trim($wrkdata['saveddata']);
         if (strLen($wrkTestData) != 0)
         {
            $wrkAWSFileName = $wrkdata['savedfilename'];
            $wrkFileName = $wrkdata['savedfilename'];
            $wrkTheSavedData  =   $wrkdata['saveddata'];
            $wrkProdFileLocation = $folder_path . $wrkFileName;
            $wrkAWSFileLocation = $_SESSION['AgencyAWS'] . $wrkFileName;
            $strDataToWrite = $folder_path . $wrkFileName;
         
            echo '<BR><BR>$wrkFileName: ' . $wrkFileName;
            echo '<BR><BR>$wrkProdFileLocation: ' . $wrkProdFileLocation;
            $_SESSION['GlobalAgencyArray'][$index] = array(
                   'strAgencyFileName' => '',
                   'strAgencySupplierCode' => '',
                   'strAgencyConfNbr' => '',
                   'strAgencyStatus' => ''); 
           
           //WRITE TO FILE
            file_put_contents($wrkProdFileLocation, $wrkTheSavedData) or die('FPUT CONTENTS FAILED');
            chmod($wrkProdFileLocation,0777);
            
            // UPDATE AGENCY INSERT ARRAY
            $strTmpNameArray = ($_SESSION['GlobalAgencyArray'][$index]);
            array_push($strTmpNameArray,$wrkFileName,$strSupplierCode,$strConfirmNbr,$strStatus);
            $index++;
            $strTmpCount = ($strTmpCount +1);
         } 
        }
      
      
        $_SESSION['GlobalAgencyIndex'] = ($_SESSION['GlobalAgencyIndex'] + $strTmpCount);
        echo'<br> $_SESSION[GlobalAgencyIndex]: '. $_SESSION['GlobalAgencyIndex'];
     
    // SANTIZE ARRAY
      $tmpWorkArray = $_SESSION['GlobalAgencyArray'];
      $_SESSION['GlobalAgencyArray'] = array_filter($tmpWorkArray);
     
      $strindex = 0;
      ECHO '<br><br>READING BACK ($_SESSION[GlobalAgencyArray]';
      $strTmp = $_SESSION['GlobalAgencyArray'];
      print_r($_SESSION['GlobalAgencyArray']);
      $strStopNbr =  $strTmpCount;
     /* 
       while($strindex <= $strStopNbr) 
      {
          echo '<BR><BR================================';
         echo '<BR>THE strAgencyFileName: ' . $_SESSION['GlobalAgencyArray'][$strindex]['strAgencyFileName'];
         echo '<BR>THE strAgencySupplierCode: ' . $_SESSION['GlobalAgencyArray'][$strindex]['strAgencySupplierCode'];
         echo '<BR>THE strAgencyConfNbr: ' . $_SESSION['GlobalAgencyArray'][$strindex]['strAgencyConfNbr'];
         echo '<BR>THE strAgencyStatus: ' . $_SESSION['GlobalAgencyArray'][$strindex]['strAgencyStatus'];
            $strindex ++;
       }
      */    
  
}
I know this can be done, I just haven't been able to get  the coding right.
And I know I will have to update its index after a function has added to it.
But I think that would be just a matter of updating as I load the array.
Any help would be appreciated. It's urgent.
Thank you in advance.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros