So my config is something like this (pretty much stripped, but it should be understandable): Code: --- hello: test: imarray: "value" meizarray: [] ... What I'm trying to do this is: Check if test (hello.test) exists Get and set value of meizarray For them, I tried following codes (once again stripped): Code: if(in_array(["hello"]["test"], Code::getArray())) { //code } Code: $testarray = new Config(".../testarray.yml", Config::YAML); $key = "hello.test.meizarray"; $testarray->setNested($key, $testarray->getNested($key)[] = "value"); $testarray->save(); And yeah, as expected, they didn't do their job. How can I make them working?
You should use isset() to check if "test" exists. PHP: if(isset(Code::getArray()["hello"]["test"])){ //...} Also, your setNested might be wrong. PHP: $array = [];$value = $array[] = "value";//$value is "value", and not ["value"]//Similarly,$array = $config->getNested($key);$array[] = "value";//$array is ["value"], considering $array is [].$config->setNested($key, $array);
Mind also posting a solution for getting and setting the value of (adding an element to) meizarray? The problem what I'm having with that part is trying to add the element to the array with the code above makes the array to turn into a string. I could add some hacks to convert if it's string, but I don't think that's worth to do for this. Afaik array_push would work too, but I don't want to use that method. Edit: Well, nevermind this. Again, thanks for the answer!