I don't know if the title explains it very well, so here's what I'm trying to achieve.
With this script people can change the value of configuration variables on the fly like so:
Config::write('General.load', array('plugin1','plugin2'), true);
In that example, it changes the General.load config variable to an array, and sets the 3rd param to true, which means that it can be saved.
What I'm trying to incorporate is a method the save part, when a user calls Config::save()
it loops through any config variables that were written to and which have had the 3rd parameter set to true.
It works perfect for booleans, strings, ints, floats etc. But when it comes to arrays, by default, it would just write "Array" to the file, instead of "array('plugin1','plugin2')".
So I went ahead and began developing a little script that converts arrays to a string based array.
Here is the function (I had to put it on pastebin, formatted strange here): http://pastebin.com/HsUG9n5D
It works, to a degree.
If you supply it with something like this:
$array_to_string = ''; $array = array( 'welcome', 'to', 'my', array('website') ); array_build($array_to_string, $array, 0); die($array_to_string);
It will output:
array('welcome', 'to', 'my', array('website')),
It nearly worked. However if I input something like this:
$array_to_string = ''; $array = array( 'welcome', 'to', 'my', array('website'), array(array('goodbye', 'foo' => 'bar')) ); array_build($array_to_string, $array, 0); die($array_to_string);
The output is:
array('welcome', 'to', 'my', array('website')array(array('goodbye', 'foo' => 'bar'), ))
I've gone over the code, and I'm not quite sure what I can do to fix it. Variable referencing is still a tad complicated for me.
If anyone has any ideas on what I've done wrong, let us know.
Cheers.