I am coding a PHP function, and I would like to ask a question. I have a problem with exploding a string in a particular way. I have tried to explain as well as I can down below.
What is this?
Well.. I am working on a solution to decrease the number of tables on my website. I can turn the table for admin rights into one field in the user table. However, I will then need to explode the text field into an array when loading the website. The code is looking like:
<?php
$string = "server1=(ban=(perm=false,normal=true),edit=true,delete=false),adminlog=true,server2=(ban=(perm=false,normal=true),edit=false,delete=true)";
function parseRights( $s="" ){
$context = array();
// code here
}
print_r(parseRights($string));
?>
Basically, I would want the result to be:
Array
(
[server1] => Array
(
[ban] => Array
(
[perm] => false
[normal] => true
)
[edit] => true
[delete] => false
)
[adminlog] => true
[server2] => Array
(
[ban] => Array
(
[perm] => false
[normal] => false
)
[edit] => false
[delete] => true
)
)
True and false should be PHP true and false. If written out like that, I know it will show 1 where true are, and nothing where 0 are.. but it's just to show you what I would like the array to look like after run through the function. I would like it to be able to create an "infinite" array, with each new parentheses creating a new array. Of cource I would gladly accept other ways to distinguish the correct rights if the function would work in the same manner.