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

  • Home
  • SEARCH
  • 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 6795355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:20:03+00:00 2026-05-26T18:20:03+00:00

Need to write (using fwrite()) some settings into php file in format: $var[‘key’][‘key’][‘key’] =

  • 0

Need to write (using fwrite()) some settings into php file in format:

$var['key']['key']['key'] = false; // bool
$var['key']['key'] = 'string'; // string
$var['key'] = 1; // numeric

Have nested php array for this

The code will override some values, defined above in the file, Var_export() useless in my case.

Any nice solution?

  • 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-26T18:20:04+00:00Added an answer on May 26, 2026 at 6:20 pm

    I answered this question in Perl before — I guess I could just port the essentials of the answer to PHP:

    function dump_array_recursive ( $prefix, $var ) {
        if ( is_array( $var ) && !empty( $var ) ) {
            foreach ($var as $key => $val) {
                $prefix_key = $prefix . "[" . var_export( $key, true ) . "]";
                dump_array_recursive( $prefix_key, $val );
            }
        } else {
            echo "$prefix = " . var_export( $var, true ) . ";\n";
        }
    }
    
    // example call:
    dump_array_recursive( '$foo', $foo );
    

    This is a little bit simpler than the Perl version, since PHP has only one array type and no scalar references to worry about. I also decided not to try collecting the output, but simply used echo; you can replace it with fwrite() if you want, or just use output buffering to catch the result in a string.

    Ps. Note that, while the output of this function usually contains one line for each value, this is not guaranteed: the output of var_export() might contain newlines, which will be passed to the output. Two cases which I’ve found to trigger such behavior include array keys with newlines in them and empty arrays, which for some reason are exported as "array (\n)" instead of just "array()".

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

Sidebar

Related Questions

I need to write an error log to a XML file using Visual Basic
I am using iText to write a PDF. In some cases, I need to
Using ASP.net, how do you write ANSI characters to a text file? I need
I need to write data to a binary file using C's I/O functions. The
I need to write some dll that will be loaded into some existing system
I need to write some code using some for-loops which tests the values of
I need to write a web application using SQL Server 2005, asp.net, and ado.net.
I need to write, in JavaScript (I am using jQuery), a function that is
I need to write, or find, a script to create a Debian package, using
I'm using Dev C++ to write a simple C program and I need to

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.