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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:50:13+00:00 2026-05-16T18:50:13+00:00

I have a array that I am writing to a file using var_export() .

  • 0

I have a array that I am writing to a file using var_export(). I reload the array every time the script starts. However, whenever I try to reference a variable inside the array it returns ‘a’, I can do a print_r() and see the array just fine, I just can not access the variable I want. Here is the saved output:

array (
  'timestamp' => '1283882964',
  'files_submitted' => 2943,
  'errors' => array (
                     '/WebFS/xx.doc' => array (
                                                                                                                                                         'STATUS' => 400,
                                                                                                                                                  ),
                     'WebFS/xx.doc.doc' => array (
                                                                                                                                                                  'STATUS' => 400,
                                                                                                                                                            ),
              )
)

Here is the code I use to save:

function add_log_entry($filename,$return_arr) {
        //$timestamp = strval(mktime());
        $return_arr['timestamp'] = mktime();
        $return_str = var_export($return_arr,true);
        return file_put_contents($filename, $return_str);
}

Here is the code I use to recall the array:

function get_log_entry($filename) {

        $var_str = file_get_contents($filename);
        eval("\$return_var = \$var_str;");
        die($return_var['timestamp']);
        return $return_var;
}

You can see I put the die() in the recall code and this is where the ‘a’ is coming from.

Thanks to whom ever responds.

Ben

  • 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-16T18:50:14+00:00Added an answer on May 16, 2026 at 6:50 pm


    use the php functions serialize and unserialize, no need to write your own hacks using var_export and eval (apart from the security implications)

    example code:

     file_put_contents($filename, serialize($array));
     $array = unserialize(file_get_contents($filename));
    

    Using serialize/unserialize might impose a security risk. To serialize simple arrays/data structures it’s better to use the json_encode function:

     file_put_contents($filename, json_encode($array));
     $array = json_decode(file_get_contents($filename), TRUE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that is produced from people wanting to reserve a time
I have an array that was populated by this script : var imgs =
I have a file that I'm using to log IP addresses for a client.
I have some code that reads from an ini file in Javascript, using activex
So I am writing a C# console application. I have a text file that
Hey Im writing to a text file using file i/o using an array of
I am writing to a binary file using a struct that just contains a
I am writing a script in php4 that downloads a xml file that has
I have a program that I'm writing where I am using another company's library
I have an array that contains @sign in the object. I can't access that

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.