So this probably has been asked before, or I might just be using arrays on a completely weird way. Anyhow, what I'm trying to do is have one array, let's say.. $replacements = array();
This array includes all the data of keys and replacements. Don't know how to describe it but this is how the idea was taken from: click -- Now, let's say I've got this array as stated above, I'm trying to have inside of my function that appends to the array, an option that allows you to make one single key restricted to a dynamic set of pages. This is how I'd imagine the array to look like:
array() {
["key1"] => "result"
["key2"] => "result2"
["key3 etc"] => "result3 etc"
}
That'd be an array of the keys without any page restrictions specified, and this is how I'd imagine the array to be when I've appended additional arrays for page restricted keys.
array() {
["key1"] => "result"
["key2"] => "result2"
["key3 etc"] => "result3 etc"
"homepage" = array() {
["home_key1"] => "this is a key in the homepage only"
["two_page_restricted"] => "this is a replacement in two restricted pages only"
},
"newspage" = array() {
["two_page_restricted"] => "this is a replacement in two restricted pages only"
}
}
I'm not sure if anything I've said so far makes any sense, but I guess you get the picture.. This is what I've got so far for a basic key replacement:
function addTranslation($key, $replacement, $restricted = null) {
if($restricted == null)
array_push($this->translations, $key, $replacement);
//else
//array_push($this->translations, )
}
In the end, what I'm trying to accomplish is that if $restricted
isn't null then append from it to $this->translations
without interfering with other keys.. Thanks in advance for any assistance effort.
Edit: If it helps, this is how I'd use the function:
For two pages:
$class->addTranslation("{key}", "this is a key", array("homepage", "newspage");
For any page:
$class->addTranslation("{key}", "this is a key");
Edit2: For clarifications, this is PHP not JavaScript.